2017-05-26 38 views
0

我工作的一種方式來獲得基於其IP機器的MAC地址,所以我結合使用Python和Scapy的:蟒蛇3 - 基於IP的MAC地址 - 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 

當我運行此方法:

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

它總是返回:

Couldn't Find MAC Address 

我從我的linux此代碼。 使用ping我已經確定,我可以訪問網絡中的其他機器。

有沒有我從文檔中遺漏的東西?

感謝和問候

+1

什麼問題? – moritzg

+0

好吧,API已經沒了?或者爲什麼我不能從IP地址獲取MAC地址? –

+0

我試着通過查看ARP-Table來獲得MAC,看看[這裏](http://python-arptable.readthedocs.io/en/latest/readme.html)。 「ARP表」將IP地址轉換爲MAC – moritzg

回答

0

首先,嘗試

except Exception as e: 
    print e 

或更好

logger.exception(e)

看到錯誤的詳細信息,下一次嘗試以root身份運行。