|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# http://trac.secdev.org/scapy/ticket/301 |
| 4 | + |
| 5 | +# scapy.contrib.description = RIPng |
| 6 | +# scapy.contrib.status = loads |
| 7 | + |
| 8 | +from scapy.packet import * |
| 9 | +from scapy.fields import * |
| 10 | +from scapy.layers.inet import UDP |
| 11 | +from scapy.layers.inet6 import * |
| 12 | + |
| 13 | +class RIPng(Packet): |
| 14 | + name = "RIPng header" |
| 15 | + fields_desc = [ |
| 16 | + ByteEnumField("cmd", 1, {1 : "req", 2 : "resp"}), |
| 17 | + ByteField("ver", 1), |
| 18 | + ShortField("null", 0), |
| 19 | + ] |
| 20 | + |
| 21 | +class RIPngEntry(Packet): |
| 22 | + name = "RIPng entry" |
| 23 | + fields_desc = [ |
| 24 | + ConditionalField(IP6Field("prefix", "::"), |
| 25 | + lambda pkt: pkt.metric != 255), |
| 26 | + ConditionalField(IP6Field("nexthop", "::"), |
| 27 | + lambda pkt: pkt.metric == 255), |
| 28 | + ShortField("routetag", 0), |
| 29 | + ByteField("prefixlen", 0), |
| 30 | + ByteEnumField("metric", 1, {16 : "Unreach", |
| 31 | + 255 : "next-hop entry"}) |
| 32 | + ] |
| 33 | + |
| 34 | +bind_layers(UDP, RIPng, sport=521, dport=521) |
| 35 | +bind_layers(RIPng, RIPngEntry) |
| 36 | +bind_layers(RIPngEntry, RIPngEntry) |
| 37 | + |
| 38 | +if __name__ == "__main__": |
| 39 | + from scapy.main import interact |
| 40 | + interact(mydict=globals(), mybanner="RIPng") |
| 41 | + |
0 commit comments