File: ripng.py

package info (click to toggle)
scapy3k 0.20-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,524 kB
  • ctags: 6,972
  • sloc: python: 39,500; makefile: 74; sh: 11
file content (41 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python

# http://trac.secdev.org/scapy/ticket/301

# scapy.contrib.description = RIPng
# scapy.contrib.status = loads

from scapy.packet import *
from scapy.fields import *
from scapy.layers.inet import UDP
from scapy.layers.inet6 import *

class RIPng(Packet):
    name = "RIPng header"
    fields_desc = [
                    ByteEnumField("cmd", 1, {1 : "req", 2 : "resp"}),
                    ByteField("ver", 1),
                    ShortField("null", 0),
            ]

class RIPngEntry(Packet):
    name = "RIPng entry"
    fields_desc = [
                    ConditionalField(IP6Field("prefix", "::"),
                                            lambda pkt: pkt.metric != 255),
                    ConditionalField(IP6Field("nexthop", "::"),
                                            lambda pkt: pkt.metric == 255),
                    ShortField("routetag", 0),
                    ByteField("prefixlen", 0),
                    ByteEnumField("metric", 1, {16 : "Unreach",
                                                255 : "next-hop entry"})
            ]

bind_layers(UDP,        RIPng,          sport=521, dport=521)
bind_layers(RIPng,      RIPngEntry)
bind_layers(RIPngEntry, RIPngEntry)

if __name__ == "__main__":
    from scapy.main import interact
    interact(mydict=globals(), mybanner="RIPng")