-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathprocessarp.py
31 lines (24 loc) · 1.27 KB
/
processarp.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
#!/usr/bin/python
#Author: Suraj Patil
#Version: 2.0
#Date: 27th March 2014
#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
#modular design, which makes it easy to include this source into another program, or to extend this one
from scapy.all import *
def main():
pcap_path = raw_input('Path of pcap file: ') # enter the path where you stored the pcap file
file_path = raw_input('Enter target file name') #enter the path where you want to create a csv file
process(pcap_path, file_path)
def process(pcap_path, file_path):
try:
file = open(file_path+'.csv','w') #tries to opens the file in read mode
pkts = rdpcap(pcap_path) #inbuilt function of scapy to read pcap files
for i in range(len(pkts)):
if ARP in pkts[i]: #checks if the packet is an ARP packet or not
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))
print 'file write complete'
#Timestamp, source MAC address, source IP address, Destination MAC address, Destination IP address
file.close()
except:
print 'some error occured'
main()