netinterface.py - qNFCpの屋
qNFCpの屋
October 26, 2022

import netifaces

print("Default gateway:", netifaces.gateways().get('default')netifaces.AF_INET)

ifaces = netifaces.interfaces()
for ifa in ifaces:

print("Network interface: ",ifa)
addrs = netifaces.ifaddresses(ifa)

if ifa == 'lo':
    del addrs[netifaces.AF_LINK]

for family, addresses in addrs.items():
    for current_addr in addresses:
        if family == netifaces.AF_LINK:
            print("  MAC address:", current_addr.get('addr'))
        else:
            print("  IP address:", current_addr.get('addr'))

        if ifa == 'lo':
            print("\t Peer:", current_addr.get('peer'))
        else:
            print("\t Broadcast address:", current_addr.get('broadcast'))
        print("\t Subnet mask:", current_addr.get('netmask'))
暂无评论

添加新评论

Title - Artist
0:00