Can I just broadcast a specific message in my own network in python?
I just want to broadcast a udp 开发者_JS百科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))
精彩评论