Skip to content

Instantly share code, notes, and snippets.

@phoddie
Created January 18, 2021 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoddie/c556d32e3c69370ff3e904cd02e41a99 to your computer and use it in GitHub Desktop.
Save phoddie/c556d32e3c69370ff3e904cd02e41a99 to your computer and use it in GitHub Desktop.
Moddable SDK - UDP example
import {Socket} from "socket";
import Timer from "timer"
const socket = new Socket({kind: "UDP"});
socket.callback = function(message, value) {
if (Socket.readable !== message)
return;
const buffer = this.read(ArrayBuffer);
const longs = new Uint32Array(buffer);
trace(`Received ${longs[0]}\n`);
}
let count = 0;
Timer.repeat(() => {
const longs = Uint32Array.of(count++);
socket.write("10.0.1.8", 31337, longs.buffer);
}, 100)
{
"include": [
"$(MODDABLE)/examples/manifest_base.json",
"$(MODDABLE)/examples/manifest_net.json"
],
"modules": {
"main": "./main"
}
}
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Author: David Manouchehri <manouchehri@protonmail.com>
# This script will always echo back data on the UDP port of your choice.
# Useful if you want nmap to report a UDP port as "open" instead of "open|filtered" on a standard scan.
# Works with both Python 2 & 3.
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = '0.0.0.0'
server_port = 31337
server = (server_address, server_port)
sock.bind(server)
print("Listening on " + server_address + ":" + str(server_port))
while True:
payload, client_address = sock.recvfrom(1024)
print("Echoing data back to " + str(client_address))
sent = sock.sendto(payload, client_address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment