-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscapy_prestart.py
58 lines (51 loc) · 1.24 KB
/
scapy_prestart.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# SCAPY Startup File for Barefoot Academy
#
# (c) Barefoot Networks, 2018-
# All Rights Reserved
##########################################
#
# Prevent Scapy from discarding 802.1q (VLAN) tags
#
conf.use_pcap = True
#
# Load additional Scapy Modules
#
#load_contrib("bfd")
load_contrib("mpls")
load_contrib("vxlan")
#load_contrib("nvgre")
#load_contrib("erspan")
load_contrib("igmp")
load_contrib("geneve")
#
# Create convenient variables, based on available VETH or Dummy Interfaces
#
import os
global all_ports
all_ports=[]
for iface in os.listdir('/sys/class/net'):
if iface.startswith("veth"):
if int(iface[4:]) % 2:
exec("{} = '{}'".format(iface, iface))
all_ports.append(iface)
if iface.startswith("port"):
exec("{} = '{}'".format(iface, iface))
all_ports.append(iface)
if iface.startswith("cpu_"):
exec("{} = '{}'".format(iface, iface))
all_ports.append(iface)
def iface_num(iface):
num = ''
for c in iface:
if c.isdigit():
num += c
return int(num)
all_ports.sort(key=iface_num)
print("""
Found the following interfaces:
{}
Created scapy.main.all_ports[] and scapy.main.veth*
To access them, type:
from scapy.main import *
""".format(all_ports))