环境:
Linux环境:安装scapy, 执行scapy
安装scapy
yum install python3-pip (安装python3 pip)
pip3 install --upgrade pip
yum remove python-pip(删除pip)
pip3 install scapy (安装scapy)
简介:
send : Send packets at layer 3
sendp : Send packets at layer 2
sr : Send and receive packets at layer 3
sr1 : Send packets at layer 3 and return only the first answer
srp : Send and receive packets at layer 2
srp1 : Send and receive packets at layer 2 and return only the first answer
send:在第3层发送数据包
sendp:在第2层发送数据包
sr:在第3层发送和接收数据包
sr1:在第3层发送数据包,只返回第一个响应包
srp:在第2层发送和接收数据包文章来源:https://www.toymoban.com/news/detail-466223.html
srp1:在第2层发送和接收数据包,只返回第一个响应包文章来源地址https://www.toymoban.com/news/detail-466223.html
源码:
>>> sr(IP(dst="192.168.6.211")/ICMP())
Begin emission:
Finished sending 1 packets.
.*
Received 2 packets, got 1 answers, remaining 0 packets
(<Results: TCP:0 UDP:0 ICMP:1 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>)
>>> sr1(IP(dst="192.168.6.211")/ICMP())
Begin emission:
Finished sending 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
<IP version=4 ihl=5 tos=0x0 len=28 id=55498 flags= frag=0 ttl=64 proto=icmp chksum=0x131f src=192.168.6.211 dst=192.168.6.212 |<ICMP type=echo-reply code=0 chksum=0xffff id=0x0 seq=0x0 |<Padding load='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |>>>
>>>
>>> srp(Ether()/IP(dst="192.168.6.211"))
Begin emission:
Finished sending 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
(<Results: TCP:0 UDP:0 ICMP:1 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>)
>>> srp1(Ether()/IP(dst="192.168.6.211"))
Begin emission:
Finished sending 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
<Ether dst=00:0c:29:12:73:7e src=00:0c:29:e8:9c:dc type=IPv4 |<IP version=4 ihl=5 tos=0xc0 len=48 id=59752 flags= frag=0 ttl=64 proto=icmp chksum=0x1ad src=192.168.6.211 dst=192.168.6.212 |<ICMP type=dest-unreach code=host-prohibited chksum=0xfcf5 reserved=0 length=0 nexthopmtu=0 unused='' |<IPerror version=4 ihl=5 tos=0x0 len=20 id=1 flags= frag=0 ttl=64 proto=hopopt chksum=0xebf1 src=192.168.6.212 dst=192.168.6.211 |>>>>
>>>
>>> send(IP(dst="192.168.6.211")/ICMP())
.
Sent 1 packets.
>>> sendp(Ether()/IP(dst="192.168.6.211"))
.
Sent 1 packets.
>>>
到了这里,关于Python scapy二层、三层发送接收数据包的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!