Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I just broadcast a specific message in my own network in python?

Tags:

python

I just want to broadcast a udp message on a specific port on my network. How can I accomplish this in python?

like image 736
sia Avatar asked May 11 '10 09:05

sia


1 Answers

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))
like image 102
fmark Avatar answered Sep 22 '22 02:09

fmark