Python-ネットワークインタフェース
3823 ワード
1台のマシンに複数のインタフェースがある場合は、名前、ステータスなどを追跡する必要があります.Pythonでは、インタフェースとそのステータスをリストできます.
import netifaces
print(netifaces.interfaces())
print(netifaces.ifaddresses('{3E9F7770-8FDD-4839-B7F1-1D86CB928E77}'))
#
print(netifaces.AF_LINK)
#
print(netifaces.ifaddresses('{6299FEF2-B4B2-4E19-A750-53014D88E109}'))
print(netifaces.ifaddresses('{258472E2-2EA9-4961-A9C5-93727E4B040A}'))
print(netifaces.ifaddresses('{C4F434E0-958A-40C2-839B-A01D49288B79}'))
print(netifaces.ifaddresses('{DBD31960-1307-4A3F-80B5-C9FE53AD0BA2}'))
print(netifaces.ifaddresses('{76435632-B62F-45EA-8290-A9096DA8A00D}'))
print(netifaces.ifaddresses('{777EFC8F-4CF5-48A6-8C67-30C410EB96DA}'))
print(netifaces.ifaddresses('{FC691F55-CD02-11E8-BFF0-806E6F6E6963}'))
-----------------------------------------------------------------------
['{6299FEF2-B4B2-4E19-A750-53014D88E109}', '{3E9F7770-8FDD-4839-B7F1-1D86CB928E77}', '{258472E2-2EA9-4961-A9C5-93727E4B040A}', '{C4F434E0-958A-40C2-839B-A01D49288B79}', '{DBD31960-1307-4A3F-80B5-C9FE53AD0BA2}', '{76435632-B62F-45EA-8290-A9096DA8A00D}', '{777EFC8F-4CF5-48A6-8C67-30C410EB96DA}', '{FC691F55-CD02-11E8-BFF0-806E6F6E6963}']
{-1000: [{'addr': '50:2b:73:dc:6a:d2'}], 23: [{'addr': 'fe80::c586:cb1a:abb3:5ec6%4', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%4'}]}
-1000
{-1000: [{'addr': '1c:1b:0d:79:23:39'}], 23: [{'addr': 'fe80::c978:93f2:e53b:a255%9', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%9'}]}
{-1000: [{'addr': '52:2b:73:dc:6c:a1'}], 23: [{'addr': 'fe80::547:caf9:4064:b769%40', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%40'}]}
{-1000: [{'addr': '00:50:56:c0:00:01'}], 23: [{'addr': 'fe80::b50b:de49:3158:7384%17', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%17'}], 2: [{'addr': '192.168.88.1', 'netmask': '255.255.255.0', 'broadcast': '192.168.88.255'}]}
{-1000: [{'addr': '00:50:56:c0:00:08'}], 23: [{'addr': 'fe80::d49c:2a0e:e31e:540f%18', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%18'}], 2: [{'addr': '192.168.118.1', 'netmask': '255.255.255.0', 'broadcast': '192.168.118.255'}]}
{-1000: [{'addr': '50:2b:73:dc:6c:a1'}], 23: [{'addr': 'fe80::4cf:8385:a986:ac9a%10', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%10'}], 2: [{'addr': '192.168.0.197', 'netmask': '255.255.255.0', 'broadcast': '192.168.0.255'}]}
{-1000: [{'addr': '50:2b:73:dc:6c:a1'}], 23: [{'addr': 'fe80::848e:99a3:9d5b:89d9%45', 'netmask': 'ffff:ffff:ffff:ffff::/64', 'broadcast': 'fe80::ffff:ffff:ffff:ffff%45'}], 2: [{'addr': '192.168.137.1', 'netmask': '255.255.255.0', 'broadcast': '192.168.137.255'}]}
{-1000: [{'addr': ''}], 23: [{'addr': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128', 'broadcast': '::1'}], 2: [{'addr': '127.0.0.1', 'netmask': '255.0.0.0', 'broadcast': '127.255.255.255'}]}