Created
September 28, 2013 18:21
-
-
Save sorz/6744884 to your computer and use it in GitHub Desktop.
Send UDP packets from any custom port (using libnet). Used for UDP hole punching on linux servers (when the local UDP port is being used).
This file contains hidden or 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 python | |
#encoding: utf-8 | |
import libnet | |
from libnet.constants import RAW4, RESOLVE, IPV4_H, UDP_H, IPPROTO_UDP | |
IFACE = 'wlan2' # Sending via the interface. | |
def sendto(sport, address): | |
l = libnet.context(RAW4, IFACE) | |
dest_ip = l.name2addr4(address[0], RESOLVE) | |
l.build_udp(sp=sport, dp=address[1], | |
payload='\x00hehe' | |
l.autobuild_ipv4(len=(IPV4_H + UDP_H), | |
prot=IPPROTO_UDP, dst=dest_ip) | |
l.write() | |
if __name__ == '__main__': | |
sendto(6000, ('vpn.sorz.org', 6001)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment