forked from cbrenton/564NetworkVisualization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetflowgen.py
More file actions
52 lines (44 loc) · 2.07 KB
/
netflowgen.py
File metadata and controls
52 lines (44 loc) · 2.07 KB
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
from struct import pack, pack_into, unpack
import socket
from array import array as arr
def IPtoBinary(addr):
return unpack("!L", socket.inet_aton(addr))[0]
version = 5
numFlows = int(raw_input("Enter number of flows: "))
uptime = int(raw_input("Enter device uptime (millis): "))
epochMillis = int(raw_input("Enter system clock in millis (since Epoch): "))
epochNano = int(raw_input("Residual nanoseconds (since Epoch): "))
totalFlowsSeen = int(raw_input("Total flows seen since boot: "))
engineType = int(raw_input("Engine type: "))
engineID = int(raw_input("Engine ID: "))
samplingInterval = int(raw_input("Sampling Interval: "))
pktPayload = arr("c", (24 + (numFlows * 48)) * "\0")
pack_into("!HHLLLLBBH", pktPayload, 0, version, numFlows, uptime, epochMillis, epochNano, totalFlowsSeen, engineType, engineID, samplingInterval)
offset = 24
for i in range(numFlows):
print "=== Flow #"+str(i+1)+" ==="
srcIP = IPtoBinary(raw_input("Source IP: "))
dstIP = IPtoBinary(raw_input("Destination IP: "))
nextIP = IPtoBinary(raw_input("IP of next hop: "))
ifIn = int(raw_input("SNMP Input Index: "))
ifOut = int(raw_input("SNMP Output Index: "))
numPkts = int(raw_input("Number of Packets in Flow: "))
l3bytes = int(raw_input("Total Layer 3 Bytes: "))
flowStart = int(raw_input("Flow Start Time: "))
flowEnd = int(raw_input("Flow End Time: "))
srcPort = int(raw_input("Source Port: "))
dstPort = int(raw_input("Destination Port: "))
tcpFlags = int(raw_input("TCP Flags: "))
ipProt = int(raw_input("IP Protocol Type: "))
tos = int(raw_input("Type of Service (ToS): "))
srcAS = int(raw_input("Source AS: "))
dstAS = int(raw_input("Destination AS: "))
srcNM = int(raw_input("Source Netmask (CIDR): "))
dstNM = int(raw_input("Destination Netmask (CIDR): "))
pack_into("!LLLHHLLLLHHBBBBHHBBH", pktPayload, offset, srcIP, dstIP, nextIP,\
ifIn, ifOut, numPkts, l3bytes, flowStart, flowEnd, srcPort, dstPort, 0, tcpFlags, ipProt,\
tos, srcAS, dstAS, srcNM, dstNM, 0)
offset += 48
fileName = open(raw_input("Output File: "), "wb")
fileName.write(pktPayload)
fileName.close()