Last active
May 12, 2022 12:28
-
-
Save domiko96/263de0d15a5e84292fa385217ab7b097 to your computer and use it in GitHub Desktop.
Send udp packets with python
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
import socket | |
from time import sleep | |
def main(): | |
interfaces = socket.getaddrinfo(host=socket.gethostname(), port=None, family=socket.AF_INET) | |
allips = [ip[-1][0] for ip in interfaces] | |
msg = b"spammy message nruonaeoiaestosdiaeoddiaobdipiaefobdiaeoni" | |
sport = 35424 | |
dport = 35424 | |
while True: | |
for ip in ["192.168.2.206", "192.168.2.227"]: | |
print(f"sending on {ip} from port {sport} to port {dport}") | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # UDP | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
sock.bind(("192.168.2.100", sport)) | |
sock.sendto(msg, (ip, dport)) | |
sock.close() | |
sleep(0.05) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment