Skip to content

Commit

Permalink
Add an ssdp scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
jgstroud committed Apr 5, 2020
1 parent 1454170 commit 565080b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ssdp_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
import socket

msg = \
'M-SEARCH * HTTP/1.1\r\n' \
'HOST:239.255.255.250:1900\r\n' \
'ST:upnp:rootdevice\r\n' \
'MX:2\r\n' \
'MAN:"ssdp:discover"\r\n' \
'\r\n'

# Set up UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 4)
#s.bind(('192.168.50.1',0))
s.settimeout(2)
s.sendto(msg, ('239.255.255.250', 1900) )
#s.sendto(msg, ('192.168.1.1', 1900) )

try:
while True:
data, addr = s.recvfrom(65507)
print addr, data
except socket.timeout:
pass

0 comments on commit 565080b

Please sign in to comment.