Skip to content

Instantly share code, notes, and snippets.

@robinfang
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save robinfang/d82908a06f422d994328 to your computer and use it in GitHub Desktop.

Select an option

Save robinfang/d82908a06f422d994328 to your computer and use it in GitHub Desktop.
发送udp广播到局域网
from socket import *
cs = socket(AF_INET, SOCK_DGRAM)
cs.bind(("10.22.13.19",54545)) # http://is.gd/73aRUm for detail
cs.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
cs.sendto('This is a test', ('255.255.255.255', 54545))
# tcpdump http://is.gd/gw2OBN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment