-
-
Save jcwarp/738ea6a00b5b1d19d4a0316663bb3151 to your computer and use it in GitHub Desktop.
Simple Python UDP echo server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# Author: David Manouchehri <[email protected]> | |
# 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), flush=True) | |
while True: | |
payload, client_address = sock.recvfrom(1000) | |
print("Echoing data back to ", str(client_address), ": ", payload) | |
sent = sock.sendto(payload, client_address) | |
print("Sent results: ", str(sent), flush=True) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=UDP Echo Service | |
After=network.target | |
[Service] | |
Type=simple | |
User=udpecho | |
ExecStart=/bin/python3 /usr/local/bin/udp_echo_server.py | |
Restart=on-abort | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment