Created
March 6, 2018 08:52
-
-
Save sgbasaraner/10afb165bec6f6e95a34cb1793ab5e32 to your computer and use it in GitHub Desktop.
python search broadcast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import fcntl | |
# Socket for scanning | |
scan_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
# Lock the socket | |
fcntl.fcntl(scan_socket, fcntl.F_SETFL, os.O_NONBLOCK) | |
# Multicast address | |
address = ("239.255.255.250", 1982) | |
def send_search_broadcast(): | |
# Searching message | |
msg = "M-SEARCH * HTTP/1.1\r\n" | |
msg = msg + "HOST: 239.255.255.250:1982\r\n" | |
msg = msg + "MAN: \"ssdp:discover\"\r\n" | |
msg = msg + "ST: wifi_bulb" | |
msg = msg.encode() | |
scan_socket.sendto(msg, address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment