Python Scapy-如何隐藏sendp\sr1的报告并获得最终结果?&x200F;
我正在与scapy合作,我开始学习如何构建数据包(如果有人在互联网上有一个很好的例子可以从中学习,那将非常好!谢谢) 我在scapy有下一个命令:Python Scapy-如何隐藏sendp\sr1的报告并获得最终结果?&x200F;,python,scapy,packets,Python,Scapy,Packets,我正在与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) 在第二层发送arp
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)
在第二层发送arp数据包。
当我执行此命令时,它会给我下一个答案:
警告:未找到IPv6目标的路由::(没有默认路由?)
开始排放:
*已完成发送1个数据包
收到1个数据包,得到1个答案,剩余0个数据包
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+"."
我想隐藏所有报告,只打印返回答案。我怎么做?
此处的部分输出来自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")