linux 解析arp数据包,linux Scapy 进行arp数据包详细过程

>> a=Ether()/ARP()

>> a.show()

###[ Ethernet ]###

dst= 00:50:56:ef:49:1f

src= 00:0c:29:e2:bb:15

type= 0x806

###[ ARP ]###

hwtype= 0x1

ptype= 0x800

hwlen= 6

plen= 4

op= who-has

hwsrc= 00:0c:29:e2:bb:15

psrc= 192.168.80.250

hwdst= 00:00:00:00:00:00

pdst= 0.0.0.0

>>arp1=srp(Ether(src=‘00:0c:29:e2:bb:15‘,dst=‘FF:FF:FF:FF:FF:FF‘)/ARP(op=1,hwsrc=‘00:0c:29:e2:bb:15‘,hwdst=‘00:00:00:00:00:00‘,psrc=‘192.168.80.250‘,pdst=‘192.168.80.251‘,))

Begin emission:

*Finished to send 1 packets.

Received 1 packets, got 1 answers, remaining 0 packets

1)>>> print(arp1)

(, )

产生收到响应与没收到响应元组;

2)查看arp1的数据类型:

>> print(type(arp1))

为元组

3)用元组的方法只打印接收报文:

>> print(arp1[0])

4)显示arp1[0]数据类型:

>> print(type(arp1[0]))

5)查看该‘scapy.plist.SndRcvList数据类型处理方法(上网查看https://fossies.org/dox/scapy-2.3.3/)用res的方法

6)产生响应数据包中的发送与接收的包,并把包res方法列出来

>> print(arp1[0].res)*第一对发送包与收发包

[(>, >>)]

7)提出收包数据

>> print(arp1[0].res[0][1])

8)查看arp1[0].res[0][1]数据类型:

>> print(type(arp1[0].res[0][1]))

9)查看该scapy.layers.l2.Ether数据类型处理方法(上网查看https://fossies.org/dox/scapy-2.3.3/)用

Static Public Attributes

string name = "Ethernet"

list fields_desc

的方法

10)用fields方法(产生相应得字典)提取收包数据:

print(arp1[0].res[0][1].fields)

{‘src‘: ‘00:0c:29:21:fd:03‘, ‘dst‘: ‘00:0c:29:e2:bb:15‘, ‘type‘: 2054}

11)用show方法读取收包数据:

print(arp1[0].res[0][1].show())

###[ Ethernet ]###

dst= 00:0c:29:e2:bb:15

src= 00:0c:29:21:fd:03

type= 0x806

###[ ARP ]###

hwtype= 0x1

ptype= 0x800

hwlen= 6

plen= 4

op= is-at

hwsrc= 00:0c:29:21:fd:03

psrc= 192.168.80.251

hwdst= 00:0c:29:e2:bb:15

pdst= 192.168.80.250

###[ Padding ]###

load= ‘\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00‘

12)用show方法读取收包数据中ARP:

>> print(arp1[0].res[0][1][1].show())

###[ ARP ]###

hwtype= 0x1

ptype= 0x800

hwlen= 6

plen= 4

op= is-at

hwsrc= 00:0c:29:21:fd:03

psrc= 192.168.80.251

hwdst= 00:0c:29:e2:bb:15

pdst= 192.168.80.250

###[ Padding ]###

load= ‘\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00‘

13)产生自己想要的print结果:

>> print(‘ip:‘ + arp1[0].res[0][1][1].fields[‘psrc‘]+ ‘ mac:‘ + arp1[0].res[0][1][1].fields[‘hwsrc‘])

ip:192.168.80.251 mac:00:0c:29:21:fd:03

14)数据结构:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值