nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 #!/usr/bin/python
3 # this script is a total hack it works and ill clean it up later
4 import sys,getopt, optparse, pdb, re
5 def raw_lines(file):
6 try:
7 raw_lines = open(file, "r")
8 except Exception:
9 print "Failed to open ",file,". Do you have the file name correct?"
10 sys.exit(1)
11 Rlines = raw_lines.readlines()
12 return Rlines
13  
14 def parse_file(file,file_name):
15 cleanup = []
16 for line in file:
17 # match=re.search("\n", line) # the next few lines are notes and can be ignored
18 # if match:
19 # line=line.replace("\n","")
20 #for x in line:
21 # clean = filter(lambda y: y != '\n', x)
22 clean = line.rstrip()
23 cleanup.append(clean)
24 try:
25 header = cleanup.index('BSSID, First time seen, Last time seen, channel, Speed, Privacy, Cipher, Authentication, Power, # beacons, # IV, LAN IP, ID-length, ESSID, Key')
26 stationStart = cleanup.index('Station MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs')
27 del cleanup[header]
28 except Exception:
29 print "You seem to have provided an improper input file"" '",file_name,"' ""Please make sure you are loading an airodump csv file and not a Pcap"
30 sys.exit(1)
31 Clients = cleanup[stationStart:] #splits off the clients into their own list
32 stationStart = stationStart - 1 #ulgy hack to make sure the heading gets deleted from end of the APs List
33 del cleanup[stationStart:]#removed all of the client info leaving only the info on available target AP's in ardump maby i should create a new list for APs?
34 lines = [cleanup,Clients]
35 return lines
36 def join_write(data,name):
37 file = open(name,'a')
38 for line in data[0]:
39 line=line.rstrip()
40 if len(line)>1:
41 file.write(line+'\n')
42 for line in data [1]:
43 if len(line)>1:
44 file.write(line+'\n')
45 file.close()
46 def showBanner():
47 print "Airodump Joiner\nJoin Two Airodump CSV Files\n\n\t-i\tInput Files [ foo_name_1 foo_name_2 foo_name_3 .....] \n\t-o\tOutput File\n"
48  
49 def file_pool(files):
50 AP = []
51 Clients = []
52 for file in files:
53 ret = raw_lines(file)
54 ret = parse_file(ret,file)
55 AP.extend(ret[1])
56 Clients.extend(ret[0])
57 lines = [AP,Clients]
58 output = sort_file(lines)
59 return output
60  
61 def sort_file(input):
62 AP = ['BSSID, First time seen, Last time seen, channel, Speed, Privacy, Cipher, Authentication, Power, # beacons, # IV, LAN IP, ID-length, ESSID, Key']
63 Clients = ['\nStation MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs']
64 Clients.extend(input[0])
65 AP.extend(input[1])
66 output = [AP,Clients]
67 return output
68  
69  
70  
71 if __name__ == "__main__":
72 if len(sys.argv) <= 1:
73 showBanner()
74 sys.exit(1)
75  
76 parser = optparse.OptionParser("usage: %prog [options] arg1 arg2 arg3 .....")
77 parser.add_option("-o", "--output", dest="output",nargs=1, help="output file to write to")
78 parser.add_option("-i", "--file", dest="filename", nargs=2 ,help="Input files to read data from requires at least two arguments")
79  
80 (options, args) = parser.parse_args()
81 filenames = options.filename
82 outfile = options.output
83 if outfile == None:
84 print "You must provide a file name to write out to. IE... -o foo.csv\n"
85 showBanner()
86 sys.exit(1)
87 elif filenames == None:
88 print "You must provide at least two file names to join. IE... -i foo1.csv foo2.csv\n"
89 showBanner()
90 sys.exit(1)
91 for file_name in args:
92 filenames += (file_name,)
93 return_var = file_pool(filenames)
94 return_var = join_write(return_var,outfile)
95  
96