I would use netifaces . Like this:
import netifaces as ni
for iface in ni.interfaces():
print('interface : {0}'.format(iface))
try:
addrs = ni.ifaddresses(iface)
for k, v in addrs[ni.AF_INET][0].items():
print(' {0} : {1}'.format(k, v))
except:
pass
gways = ni.gateways()
print('gateway: {0}'.format(gways['default'][ni.AF_INET][0]))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.