pythonくだらない話5:pythonネイティブ情報の取得

478 ワード

pythonは、ネイティブMACアドレスを取得します.
def get_mac():
    mac = uuid.UUID(int = uuid.getnode()).hex[-12:]
    mac_address = ":".join([mac[e:e+2] for e in range(0,11,2)])
    return mac_address

pythonはネイティブipアドレスを取得します:
def get_ip_config():
    name = socket.getfqdn(socket.gethostname())
    ipaddress = socket.gethostbyname(name)
    return "computer_name:"+name+",computer_ip:"+ipaddress