Skip to content

Commit e137888

Browse files
committed
Keep a record of all SSDP servers seen
1 parent d316735 commit e137888

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

debug/ssdp_client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
import struct
1111

1212
HEADERS_TO_IGNORE = [ # Generally uninteresting headers
13-
'NT', 'NTS', 'ST'
13+
'NT', 'ST'
1414
]
1515

16+
HOSTS_SEEN = {} # To keep track of unique hosts seen
17+
1618
class SSDPClient:
1719
def __init__(self, multicast_group='239.255.255.250', multicast_port=1900, interface_ip='0.0.0.0'):
1820
self.multicast_group = multicast_group
@@ -45,14 +47,22 @@ def handle_ssdp_packet(self, data, addr):
4547
decoded_data = data.decode('utf-8')
4648
print(f"\nReceived SSDP packet from {addr[0]}:{addr[1]}:")
4749
print("----------------------------------------")
50+
server_name = None
4851
for line in decoded_data.splitlines():
4952
line = line.strip()
5053
if not line:
5154
continue
55+
if line.startswith("SERVER:"):
56+
server_name = line.split("SERVER:", 1)[1].strip()
5257
if any(header in line for header in HEADERS_TO_IGNORE):
5358
continue
5459
print(line)
5560
print("----------------------------------------")
61+
62+
# Update HOSTS_SEEN with the IP address and SERVER name
63+
if server_name:
64+
HOSTS_SEEN[addr[0]] = server_name
65+
5666
except UnicodeDecodeError:
5767
print(f"\nReceived SSDP packet from {addr[0]}:{addr[1]} (unable to decode):")
5868
print(data)
@@ -62,6 +72,11 @@ def stop(self):
6272
self.sock.close()
6373
self.thread.join()
6474

75+
# Print all hosts seen
76+
print("\nHosts seen during this session:")
77+
for ip, server in HOSTS_SEEN.items():
78+
print(f"{ip}: {server}")
79+
6580
def main():
6681
ssdp_client = SSDPClient()
6782
try:

0 commit comments

Comments
 (0)