/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Administration/Linux/network/multicast/scripts/upnp-discovery.py

  • Committer: Suren A. Chilingaryan
  • Date: 2023-01-22 13:43:11 UTC
  • Revision ID: csa@suren.me-20230122134311-zqe3ft10p33wqgfv
BMC/IPMI, smarthome, multicast-routing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# simple script to enumerate UPNP devices
 
2
 
 
3
import socket
 
4
 
 
5
# M-Search message body
 
6
MS = \
 
7
    'M-SEARCH * HTTP/1.1\r\n' \
 
8
    'HOST:239.255.255.250:1900\r\n' \
 
9
    'ST:upnp:rootdevice\r\n' \
 
10
    'MX:2\r\n' \
 
11
    'MAN:"ssdp:discover"\r\n' \
 
12
    '\r\n'
 
13
 
 
14
# Set up a UDP socket for multicast
 
15
SOC = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
 
16
SOC.settimeout(2)
 
17
 
 
18
# Send M-Search message to multicast address for UPNP
 
19
SOC.sendto(MS.encode('utf-8'), ('239.255.255.250', 1900) )
 
20
 
 
21
#listen and capture returned responses
 
22
try:
 
23
    while True:
 
24
        data, addr = SOC.recvfrom(8192)
 
25
        print (addr, data)
 
26
        print "\n"
 
27
except socket.timeout:
 
28
        pass