简体   繁体   English

python 3-基于ip的mac地址-scapy

[英]python 3 - mac address based on ip - scapy

i am working on a way to obtain the mac address of a machine based on its ip, therefore i use python in combination with scapy: 我正在研究一种基于其ip获取机器的mac地址的方法,因此我将python与scapy结合使用:

def obtain_mac(IP):
        conf.verb = 0
        ans, unans = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = IP), timeout = 2, iface = interface, retry = 10)
        for snd,rcv in ans:
            return rcv.sprintf(r"%Ether.src%")
            # i also tried this, but same result
            #return rcv[Ether].src

When i run this method: 当我运行此方法时:

try:
        otherMac = obtain_mac(192.168.2.134)
except Exception:
        # some stuff
        print ("[!] Couldn't Find MAC Address")
        sys.exit(1)

it always returns: 它总是返回:

Couldn't Find MAC Address

I am running this code from my linux. 我正在从Linux运行此代码。 Using ping i already made sure, that i can access the other machine in network. 我已经使用ping确认可以访问网络中的另一台计算机。

is there anything i missed from docs? 我有什么想念的文档吗?

thanks and greetings 谢谢和问候

First, try 第一次尝试

except Exception as e:
    print e

or better 或更好

logger.exception(e)

to see the error details, next try run as root. 要查看错误详细信息,下一步尝试以root身份运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM