diff --git a/README.md b/README.md index 3b60054..89c858b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ These information are the following: The messages is formed as the following UTF-8 encoded string: ``` -BIRBOX|{ipaddr}|{hostname}|{version}|{uptime} +BIRBOX|{ipaddr}|{hostname}|{version}|{uptime in seconds} ``` The messages are broadcast to the 6969 UDP port. @@ -23,4 +23,32 @@ All you need is to listen to such packets on the network, so you can find your l ## Usage -Just start the script as a system daemon. You may have to change the interface name. \ No newline at end of file +Just start the script as a system daemon. You may have to change the interface name. + +## Receiver example + +```python3 +import socket + +client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) +client.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) +client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + +client.bind(("", 6969)) +while True: + data, addr = client.recvfrom(1500) + + src_ip = addr[0] + try: + header, self_ip, hostname, version, uptime = data.decode().split('|') + except ValueError: + continue + + if header == 'BIRBOX': + print("IP Address:",src_ip) + if src_ip != self_ip: + print("Warning! Reported and origin IP differ! Reported ip:",self._ip) + print("Hostname:", hostname) + print("Version:", version) + print("System uptime:", uptime,'sec') +``` \ No newline at end of file