Skip to content

Commit 872b557

Browse files
committed
added modular structure
1 parent edf6572 commit 872b557

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

processarp.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
#!/usr/bin/python
22

33
#Author: Suraj Patil
4-
#Version: 1.0
4+
#Version: 2.0
55
#Date: 27th March 2014
66

77
#Reads a pcap file into python using scapy and produces a csv file as output in the following format: Timestamp, source MAC address, source IP address, Destination MAC address, Destination IP address
8+
#modular design, which makes it easy to include this source into another program, or to extend this one
89

910
from scapy.all import *
1011

11-
pcap_path = raw_input('Path of pcap file: ') # enter the path where you stored the pcap file
12-
file_path = raw_input('Enter target file name') #enter the path where you want to create a csv file
12+
def main():
13+
pcap_path = raw_input('Path of pcap file: ') # enter the path where you stored the pcap file
14+
file_path = raw_input('Enter target file name') #enter the path where you want to create a csv file
15+
process(pcap_path, file_path)
1316

14-
try:
15-
file = open(file_path+'.csv','w') #tries to opens the file in read mode
16-
pkts = rdpcap(pcap_path) #inbuilt function of scapy to read pcap files
17-
for i in range(len(pkts)):
18-
if ARP in pkts[i]: #checks if the packet is an ARP packet or not
19-
file.write('%d,%s,%s,%s,%s,%d,%s\n'%( pkts[i].time, pkts[i].hwsrc, pkts[i].psrc, pkts[i].hwdst, pkts[i].pdst, pkts[i].op))
20-
print 'file write complete'
21-
#Timestamp, source MAC address, source IP address, Destination MAC address, Destination IP address
22-
file.close()
23-
except:
24-
print 'some error occured'
17+
def process(pcap_path, file_path):
18+
try:
19+
file = open(file_path+'.csv','w') #tries to opens the file in read mode
20+
pkts = rdpcap(pcap_path) #inbuilt function of scapy to read pcap files
21+
for i in range(len(pkts)):
22+
if ARP in pkts[i]: #checks if the packet is an ARP packet or not
23+
file.write('%d,%s,%s,%s,%s,%d,%s\n'%( pkts[i].time, pkts[i].hwsrc, pkts[i].psrc, pkts[i].hwdst, pkts[i].pdst, pkts[i].op))
24+
print 'file write complete'
25+
#Timestamp, source MAC address, source IP address, Destination MAC address, Destination IP address
26+
file.close()
27+
except:
28+
print 'some error occured'
29+
30+
31+
main()

0 commit comments

Comments
 (0)