开发者

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))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜