I just want to broadcast a udp message on a specific port on my network. How can I accomplish this in python?
This will only work with IPv4 networks:
BC_PORT = 12345
import sys, time
from socket import *
s = socket(AF_INET, SOCK_DGRAM)
s.bind(('', 0))
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.sendto("hello world", ('<broadcast>', BC_PORT))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With