获取网络信息
Python Get Default Gateway IP Using Netifaces: A Step Guide – Python Tutorial
python – How to get the physical interface IP address from an interface – Stack Overflow
pip install netifaces import netifaces
获取网关设备及地址:
# gets gateway of the network gws = netifaces.gateways() gateway = gws['default'][netifaces.AF_INET][0] # 默认网关地址 gateway_interface = gws['default'][netifaces.AF_INET][1] # 默认网关接口名称
获取网卡的地址:
address = netifaces.ifaddresses("interface_name")[netifaces.AF_INET][0]['addr']