Search for host with MAC-address using Python

2020-07-09 06:36发布

I'd like to search for a given MAC address on my network, all from within a Python script. I already have a map of all the active IP addresses in the network but I cannot figure out how to glean the MAC address. Any ideas?

8条回答
劫难
2楼-- · 2020-07-09 06:53

Mark Pilgrim describes how to do this on Windows for the current machine with the Netbios module here. You can get the Netbios module as part of the Win32 package available at python.org. Unfortunately at the moment I cannot find the docs on the module.

查看更多
男人必须洒脱
3楼-- · 2020-07-09 06:55

as python was not meant to deal with OS-specific issues (it's supposed to be interpreted and cross platform), i would execute an external command to do so:

in unix the command is ifconfig

if you execute it as a pipe you get the desired result:

import os
myPipe = os.popen2("/sbin/ifconfig","a")
print(myPipe[1].read())
查看更多
登录 后发表回答