Added more info to the fields
This commit is contained in:
		
							
								
								
									
										24
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								main.py
									
									
									
									
									
								
							@@ -22,33 +22,35 @@ def get_hostname() -> str:
 | 
				
			|||||||
    return socket.gethostname()
 | 
					    return socket.gethostname()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_version() -> Optional[str]:
 | 
					def get_version() -> str:
 | 
				
			||||||
    with open('/version', 'r') as f:
 | 
					    try:
 | 
				
			||||||
        for line in f:
 | 
					        with open('/version', 'r') as f:
 | 
				
			||||||
            if line.lower().startswith("version:"):
 | 
					            for line in f:
 | 
				
			||||||
                return line.split(":", 2)[1].strip()
 | 
					                if line.lower().startswith("version:"):
 | 
				
			||||||
 | 
					                    return line.split(":", 2)[1].strip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return None
 | 
					            return "u"
 | 
				
			||||||
 | 
					    except FileNotFoundError:
 | 
				
			||||||
 | 
					        return "u"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
 | 
					    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
 | 
				
			||||||
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
 | 
					    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
 | 
				
			||||||
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
 | 
					    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
 | 
				
			||||||
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"eth0")
 | 
					    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"enp3s0")
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while True:
 | 
					    while True:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ipaddr = ""
 | 
					        ipaddr = ""
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            ipaddr = get_ip_address("eth0")
 | 
					            ipaddr = get_ip_address("enp3s0")
 | 
				
			||||||
        except:
 | 
					        except:
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        message = b"BIRBOX|" + ipaddr.encode() + b"|" + str(int(get_uptime())).encode()
 | 
					        message = f"BIRBOX|{ipaddr}|{get_hostname()}|{get_version()}|{int(get_uptime())}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        sock.sendto(message, ('<broadcast>', 6969))
 | 
					        sock.sendto(message.encode("utf-8"), ('<broadcast>', 6969))
 | 
				
			||||||
        time.sleep(10)
 | 
					        time.sleep(10)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user