Added more getters
This commit is contained in:
		
							
								
								
									
										20
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								main.py
									
									
									
									
									
								
							@@ -1,29 +1,43 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
from typing import Optional
 | 
			
		||||
import socket
 | 
			
		||||
import time
 | 
			
		||||
import fcntl
 | 
			
		||||
import struct
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_ip_address(ifname):
 | 
			
		||||
def get_ip_address(ifname: str) -> str:
 | 
			
		||||
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 | 
			
		||||
    return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15].encode()))[20:24])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_uptime():
 | 
			
		||||
def get_uptime() -> float:
 | 
			
		||||
    with open('/proc/uptime', 'r') as f:
 | 
			
		||||
        uptime_seconds = float(f.readline().split()[0])
 | 
			
		||||
 | 
			
		||||
    return uptime_seconds
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_hostname() -> str:
 | 
			
		||||
    return socket.gethostname()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_version() -> Optional[str]:
 | 
			
		||||
    with open('/version', 'r') as f:
 | 
			
		||||
        for line in f:
 | 
			
		||||
            if line.lower().startswith("version:"):
 | 
			
		||||
                return line.split(":", 2)[1].strip()
 | 
			
		||||
 | 
			
		||||
    return None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    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_BROADCAST, 1)
 | 
			
		||||
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"eth0")
 | 
			
		||||
 | 
			
		||||
    print("Beaconing...")  # or something, idk i don't do english
 | 
			
		||||
 | 
			
		||||
    while True:
 | 
			
		||||
 | 
			
		||||
        ipaddr = ""
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user