Skip to content

Instantly share code, notes, and snippets.

@abdalmoez
Last active January 19, 2024 07:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdalmoez/bfc0df47f47bda90c5ac218e93be9eeb to your computer and use it in GitHub Desktop.
Save abdalmoez/bfc0df47f47bda90c5ac218e93be9eeb to your computer and use it in GitHub Desktop.
Send udp packet using python
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 1234
MESSAGE = "Hello, World!"
print ("UDP target IP:", UDP_IP)
print ("UDP target port:", UDP_PORT)
print ("message:", MESSAGE)
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE.encode(), (UDP_IP, UDP_PORT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment