1.下载scapy2.3.2
戳这里 下载
2.解压缩
ljyfree@ubuntu:~$ unzip scapy-2.3.2.zip
3.修改/scapy/all.py
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
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
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.安装
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.验证
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,原文地址http://www.sdnlab.com/16914.html