【发布时间】:2016-11-21 16:20:28
【问题描述】:
我在下面创建的 get_mac 函数有问题,它接受 IP 地址并找到它的 mac 地址,返回它或 None。
实际的python函数是:
def get_mac(ip_addr):
"get_mac is used to obtain the mac address of the target ip."
print "Getting Mac for: %s" % ip_addr
responses, unanswered = srp(Ether(dst="de:ad:be:ef:ca:fe")/ARP(pdst=ip_addr),timeout=2,retry=10)
for s,r in responses:
return r[Ether].src
return None
我认为可能有更好的方法来做到这一点。这是从 Black Hat Python 书中取出的,并利用了导入:
from scapy.all import *
from scapy.base_classes import Gen, SetGen
import scapy.plist as plist
from scapy.utils import PcapReader
from scapy.data import MTU, ETH_P_ARP
import os
import sys
import threading
import signal
对于我的整个文件文件,我一直在使用它。我正在为一个非常精细的目的创建一个自定义工具。我正在对我的伙伴运行它,通过 ipconfig 告诉我他的 IP 是 192.168.0.20,所以当运行它时,我可以看到控制台输出此信息。
....
Begin emission:
Finished to send 1 packets.
Received 12 packets, got 0 answers, remaining 1 packets
....
12 次,然后打印我告诉它的内容,因为它没有返回任何内容。
! Failed to find Target Mac
这是正确的做法吗?我的朋友给我发错了IP地址吗?我想我在ipconfig看到他给了我ipv4
我想我很好奇是否有比我最终调用的 srp() 函数更好的方法。
我使用的基本示例是 BlackhatPython 的第 52 页,名为:ARP Cache Poisoning via Scapy。
【问题讨论】:
标签: python python-2.7 networking network-programming