1 #!/usr/bin/env python 2 3 # This file is part of Scapy 4 # Scapy is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # any later version. 8 # 9 # Scapy is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with Scapy. If not, see <http://www.gnu.org/licenses/>. 16 17 # scapy.contrib.description = RIPng 18 # scapy.contrib.status = loads 19 20 from scapy.packet import * 21 from scapy.fields import * 22 from scapy.layers.inet import UDP 23 from scapy.layers.inet6 import * 24 25 class RIPng(Packet): 26 name = "RIPng header" 27 fields_desc = [ 28 ByteEnumField("cmd", 1, {1 : "req", 2 : "resp"}), 29 ByteField("ver", 1), 30 ShortField("null", 0), 31 ] 32 33 class RIPngEntry(Packet): 34 name = "RIPng entry" 35 fields_desc = [ 36 ConditionalField(IP6Field("prefix", "::"), 37 lambda pkt: pkt.metric != 255), 38 ConditionalField(IP6Field("nexthop", "::"), 39 lambda pkt: pkt.metric == 255), 40 ShortField("routetag", 0), 41 ByteField("prefixlen", 0), 42 ByteEnumField("metric", 1, {16 : "Unreach", 43 255 : "next-hop entry"}) 44 ] 45 46 bind_layers(UDP, RIPng, sport=521, dport=521) 47 bind_layers(RIPng, RIPngEntry) 48 bind_layers(RIPngEntry, RIPngEntry) 49 50 if __name__ == "__main__": 51 from scapy.main import interact 52 interact(mydict=globals(), mybanner="RIPng") 53 54