-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScan_networkcardinfo.py
21 lines (19 loc) · 1.06 KB
/
Scan_networkcardinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import netifaces
routingGateway = netifaces.gateways()['default'][netifaces.AF_INET][0]
routingNicName = netifaces.gateways()['default'][netifaces.AF_INET][1]
for interface in netifaces.interfaces():
if interface == routingNicName:
# print netifaces.ifaddresses(interface)
routingNicMacAddr = netifaces.ifaddresses(interface)[netifaces.AF_LINK][0]['addr']
try:
routingIPAddr = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr']
# TODO(Guodong Ding) Note: On Windows, netmask maybe give a wrong result in 'netifaces' module.
routingIPNetmask = netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['netmask']
except KeyError:
pass
display_format = '%-30s %-20s'
print(display_format % ("Routing Gateway:", routingGateway))
print(display_format % ("Routing NIC Name:", routingNicName))
print(display_format % ("Routing NIC MAC Address:", routingNicMacAddr))
print(display_format % ("Routing IP Address:", routingIPAddr))
print(display_format % ("Routing IP Netmask:", routingIPNetmask))