Skip to content

Instantly share code, notes, and snippets.

@zhangys-lucky
Created July 14, 2015 10:36
Show Gist options
  • Save zhangys-lucky/218a9d36c06b64abb00f to your computer and use it in GitHub Desktop.
Save zhangys-lucky/218a9d36c06b64abb00f to your computer and use it in GitHub Desktop.
python broadcast
# Send UDP broadcast packets
MYPORT = 50000
import sys, time
from socket import *
s = socket(AF_INET, SOCK_DGRAM)
s.bind(('', 0))
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
while 1:
data = repr(time.time()) + '\n'
s.sendto(data, ('192.168.1.255', MYPORT))
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment