import socket, uuid, requests, re
from dataclasses import dataclass, asdict

@dataclass
class MachineInfo:
    hostname: str
    ipAddress: str
    ID: int
    macAddress: str


def get_machine_info():
    hostname = socket.gethostname()

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    ip = s.getsockname()[0]
    s.close()

    mac = uuid.getnode()
    mac_address = ':'.join(f'{(mac >> ele) & 0xff:02x}' for ele in range(40, -1, -8))

    match = re.search(r".*-(\d+)$", hostname)
    ID = int(match.group(1)) if match else 0

    machine = MachineInfo(
        hostname=hostname,
        ipAddress=ip,
        ID=ID,
        macAddress=mac_address
    )

    return asdict(machine)

data = get_machine_info()


#change this address!
response = requests.post(
    "http://10.10.70.52:4500/boot",
    json=data
)

