Answers for "send udp packet in python"

2

python UDP send

import socket

SOURCE_IP = "192.168.1.123"
SOURCE_PORT = 5678
DESTINATION_IP = "192.168.1.124
DESTINATION_PORT = 5679

# create the socket
udp_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
udp_socket.bind((SOURCE_IP,SOURCE_PORT))

# prepare the payload
payload_hex_string = "68656c6c6f5f776f726c64" #hello_world
payload = bytes.fromhex(payload_hex_string)

#send out the packet
udp_socket.sendto(payload,(DESTINATION_IP,DESTINATION_PORT))
Posted by: Guest on May-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language