Scapy - 如何隐藏 sendp\sr1 的报告并获得最终结果?

Scapy - How can I hide the report of sendp\sr1 and just get the final?‏

我正在使用 scapy 并开始学习如何构建数据包(如果有人在互联网上有一个很好的例子可以从中学习 - 那就太好了!谢谢。)。

我在 scapy 中有下一个命令:

srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip)/Padding(load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),timeout=2)

在第2层发送arp数据包。 当我执行此命令时,它给了我下一个答案:

WARNING: No route found for IPv6 destination :: (no default route?) Begin emission: *Finished to send 1 packets.

Received 1 packets, got 1 answers, remaining 0 packets

00:50:56:e9:b8:b1

下一个代码:

def Arp_Req(ip):
        packet = srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip)/Padding(load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),timeout=2)
        try:
                packet[0][0]
                return packet[0][0][1].hwsrc
        except IndexError:
                return "(E2)CANT FIND AN ANSWER FOR "+ip+"."

我想隐藏所有报告并只打印 return 答案。我该怎么做?

由于 IPv6,此处的部分输出来自警告,您可以通过禁用 IPv6 支持(来自 scapy)来避免这种情况,但您也有函数 srp() 本身生成的输出,为此您需要设置verbose 参数:

from scapy.config import conf  
conf.ipv6_enabled = False
from scapy.all import *

def Arp_Req(ip):
    packet = srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip)/Padding(load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),timeout=2, verbose=0)
    try:
        packet[0][0]
        return packet[0][0][1].hwsrc
    except IndexError:
        return "(E2)CANT FIND AN ANSWER FOR "+ip+"."

# example
print Arp_Req("192.168.0.254")