作者简介:刘敬一,盛科网络SDN交换机产品线测试主管
1.下载scapy2.3.2
Scapy的是一个强大的交互式数据包处理程序(使用python编写)。它能够伪造或者解码大量的网络协议数据包,能够发送、捕捉、匹配请求和回复包等等。戳这里下载Scapy
2.解压缩
1 |
ljyfree@ubuntu:~$ unzip scapy-2.3.2.zip |
3.修改/scapy/all.py
1 2 3 4 5 |
ljyfree@ubuntu:~/scapy-2.3.2/scapy$ pwd /home/centec/scapy-2.3.2/scapy ljyfree@ubuntu:~/scapy-2.3.2/scapy$ vi all.py 添加一行 from contrib.all import * |
4.查看vxlan.py
此时/scapy/contrib/下,应该已经有人提交过vxlan.py
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 |
ljyfree@ubuntu:~/scapy-2.3.2/scapy$ cd contrib/ ljyfree@ubuntu:~/scapy-2.3.2/scapy/contrib$ ljyfree@ubuntu:~/scapy-2.3.2/scapy/contrib$ more vxlan.py # RFC 7348 - Virtual eXtensible Local Area Network (VXLAN): # A Framework for Overlaying Virtualized Layer 2 Networks over Layer 3 Networks # http://tools.ietf.org/html/rfc7348 # scapy.contrib.description = VXLAN # scapy.contrib.status = loads from scapy.packet import Packet, bind_layers from scapy.layers.l2 import Ether from scapy.layers.inet import UDP from scapy.fields import FlagsField, XByteField, ThreeBytesField _VXLAN_FLAGS = ['R' for i in range(0, 24)] + ['R', 'R', 'R', 'I', 'R', 'R', 'R', 'R', 'R'] class VXLAN(Packet): name = "VXLAN" fields_desc = [FlagsField("flags", 0x08000000, 32, _VXLAN_FLAGS), ThreeBytesField("vni", 0), XByteField("reserved", 0x00)] def mysummary(self): return self.sprintf("VXLAN (vni=%VXLAN.vni%)") bind_layers(UDP, VXLAN, dport=4789) bind_layers(VXLAN, Ether) ljyfree@ubuntu:~/scapy-2.3.2/scapy/contrib$ |
5.在scapy/contrib里面添加all.py
结合scapy/all.py,可以看到这里的all.py用来加载contrib/下面的各个协议定义,尤其要包含vxlan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
ljyfree@ubuntu:~/scapy-2.3.2/scapy/contrib$ more all.py from scapy.config import conf from scapy.error import log_loading import logging log = logging.getLogger("scapy.loading") def _import_star(m): mod = __import__(m, globals(), locals()) for k,v in mod.__dict__.iteritems(): globals()[k] = v _contrib_modules_ = ["bgp","igmp","igmpv3","ldp","mpls","ospf","ripng","rsvp", "vxlan"] for _l in _contrib_modules_: log_loading.debug("Loading module %s" % _l) try: _import_star(_l) except Exception,e: log.warning("can't import module %s: %s" % (_l,e)) ljyfree@ubuntu:~/scapy-2.3.2/scapy/contrib$ |
6.安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
ljyfree@ubuntu:~/scapy-2.3.2$ sudo python setup.py install running install running build running build_py running build_scripts running install_lib ... running install_scripts copying build/scripts-2.7/UTscapy -> /usr/local/bin copying build/scripts-2.7/scapy -> /usr/local/bin changing mode of /usr/local/bin/UTscapy to 775 changing mode of /usr/local/bin/scapy to 775 running install_data creating /usr/local/share/man/man1 copying doc/scapy.1.gz -> /usr/local/share/man/man1 running install_egg_info Writing /usr/local/lib/python2.7/dist-packages/scapy-2.3.2.egg-info ljyfree@ubuntu:~/scapy-2.3.2$ |
7.验证
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 |
ljyfree@ubuntu:~/scapy-2.3.2$ scapy INFO: Can't import python gnuplot wrapper . Won't be able to plot. INFO: Can't import PyX. Won't be able to use psdump() or pdfdump(). WARNING: No route found for IPv6 destination :: (no default route?) WARNING: can't import module igmp: name 'IP' is not defined IGMPv3 is still under development - Nov 2010 WARNING: can't import module igmpv3: name 'IP' is not defined WARNING: can't import module ospf: name 'IP6Field' is not defined Welcome to Scapy (2.3.2) >>> >>> >>> p = Ether()/IP()/UDP()/VXLAN() >>> p.show() ###[ Ethernet ]### dst= ff:ff:ff:ff:ff:ff src= 00:00:00:00:00:00 type= 0x800 ###[ IP ]### version= 4 ihl= None tos= 0x0 len= None id= 1 flags= frag= 0 ttl= 64 proto= udp chksum= None src= 127.0.0.1 dst= 127.0.0.1 \options\ ###[ UDP ]### sport= domain dport= 4789 len= None chksum= None ###[ VXLAN ]### flags= I vni= 0 reserved= 0x0 >>> |
--------------华丽的分割线------------------
本文系《SDNLAB原创文章奖励计划》投稿文章,该计划旨在鼓励广大从业人员在SDN/NFV/Cloud网络领域创新技术、开源项目、产业动态等方面进行经验和成果的文字传播、分享、交流。有意向投稿的同学请通过官方唯一指定投稿通道进行文章投递,投稿细则请参考《SDNLAB原创文章奖励计划》