Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python scapy中具有相同名称的层如何获得值​;分开?_Python_Scapy - Fatal编程技术网

Python scapy中具有相同名称的层如何获得值​;分开?

Python scapy中具有相同名称的层如何获得值​;分开?,python,scapy,Python,Scapy,Scapy是一个Python程序,下面是一个RIP包,它是一个RIP路由条目。它有多个路由条目。如何将字段分别放入其中 >>> rdpcap('./RIPv2.cap') <RIPv2.cap: TCP:0 UDP:12 ICMP:0 Other:0> >>> rip = rdpcap('./RIPv2.cap') >>> rip = rip[-1] >>> rip <Ether dst=01:00:5e

Scapy是一个Python程序,下面是一个RIP包,它是一个RIP路由条目。它有多个路由条目。如何将字段分别放入其中

>>> rdpcap('./RIPv2.cap')
<RIPv2.cap: TCP:0 UDP:12 ICMP:0 Other:0>
>>> rip = rdpcap('./RIPv2.cap')
>>> rip = rip[-1]
>>> rip
<Ether  dst=01:00:5e:00:00:09 src=c2:01:17:23:00:00 type=0x800 |<IP  version=4 ihl=5 tos=0xc0 len=112 id=0 flags= frag=0 ttl=2 proto=udp chksum=0xcdb2 src=10.0.0.2 dst=224.0.0.9 |<UDP  sport=route dport=route len=92 chksum=0x75a9 |<RIP  cmd=resp version=2 null=0 |<RIPEntry  AF=IP RouteTag=0 addr=10.0.0.8 mask=255.255.255.252 nextHop=0.0.0.0 metric=1 |<RIPEntry  AF=IP RouteTag=0 addr=10.0.0.12 mask=255.255.255.252 nextHop=0.0.0.0 metric=2 |<RIPEntry  AF=IP RouteTag=0 addr=192.168.2.0 mask=255.255.255.0 nextHop=0.0.0.0 metric=1 |<RIPEntry  AF=IP RouteTag=0 addr=192.168.4.0 mask=255.255.255.0 nextHop=0.0.0.0 metric=2 |>>>>>>>>
>>> rip.getlayer(RIPEntry)
<RIPEntry  AF=IP RouteTag=0 addr=10.0.0.8 mask=255.255.255.252 nextHop=0.0.0.0 metric=1 |<RIPEntry  AF=IP RouteTag=0 addr=10.0.0.12 mask=255.255.255.252 nextHop=0.0.0.0 metric=2 |<RIPEntry  AF=IP RouteTag=0 addr=192.168.2.0 mask=255.255.255.0 nextHop=0.0.0.0 metric=1 |<RIPEntry  AF=IP RouteTag=0 addr=192.168.4.0 mask=255.255.255.0 nextHop=0.0.0.0 metric=2 |>>>>
>>> entry =rip.getlayer(RIPEntry)
>>> entry.fields
{'AF': 2, 'RouteTag': 0, 'addr': '10.0.0.8', 'mask': '255.255.255.252', 'nextHop': '0.0.0.0', 'metric': 1}
rdpcap(“./RIPv2.cap”) >>>rip=rdpcap('./RIPv2.cap') >>>里普=里普[-1] >>>撕开 >>>rip.getlayer(尝试) >>>entry=rip.getlayer(try) >>>条目字段 {'AF':2,'RouteTag':0,'addr':'10.0.0.8','mask':'255.255.252','nextHop':'0.0.0.0','metric':1} 只能获取第一条路线入口的字段,如何获取其他?    
使用第二个参数:

>>> a = Ether()/IP()/ICMP(seq=0)/ICMP(seq=25)/ICMP(seq=3)
>>> a.getlayer(ICMP).seq                                
0
>>> a.getlayer(ICMP, 2).seq                             
25
>>> a.getlayer(ICMP, 3).seq                             
33
然后,您可以遍历这些层:

>>> a = Ether()/IP()/ICMP(seq=0)/ICMP(seq=25)/ICMP(seq=3)
>>> current = a[ICMP]
>>> while current:
...:     print(current.seq)
...:     current = current.getlayer(ICMP, 2)  # Use 2 otherwise it would return itself

请解释问题是什么,当我们不知道你的处境时,我们无法帮助你。在发布问题之前,请阅读本指南: