开发者

How to list network interfaces, its configuration IP,netmask and gateway in Python/Windows

I wanna develop a small application to monitor arp and scan arp list in local network.

Currently, I need to retrieve the list of network interfaces and its configuration.

Most of the time I work with Linux, so I don't know much about Win32 API, is there anyway to do this in python way ? I'm using Python 2.6 with PyQt and Scapy (has pywin32 aswell, so if you provide 开发者_运维技巧the detail way with win32, I will try)

I found pcapy.findalldevs(), but it cannot retrive configuration. I don't care much about the name, just configuration(IP,netmask) is OK.


For a cross platform solution, I've used netifaces.


Not sure exactly what info you want, but ipconfig /all certainly sounds like what you want:

import subprocess
subprocess.call('ipconfig /all')


For Linux, I use pynetlinux

pip install pynetlinux==1.1
>>> from pynetlinux import ifconfig
>>> ifconfig.Interface("eth0").get_ip()
'192.168.1.66'

Edit: This is indeed for Linux, for a cross-platform solution, see my other answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜