| 1 |
#!/usr/bin/python |
| 2 |
# this script is a total hack it works and I'll clean it up later |
| 3 |
import sys,getopt, argparse, pdb, re |
| 4 |
def raw_lines(file): |
| 5 |
try: |
| 6 |
raw_lines = open(file, "r") |
| 7 |
except Exception: |
| 8 |
print("Failed to open ",file,". Do you have the file name correct?") |
| 9 |
sys.exit(1) |
| 10 |
Rlines = raw_lines.readlines() |
| 11 |
return Rlines |
| 12 |
|
| 13 |
def parse_file(file,file_name): |
| 14 |
cleanup = [] |
| 15 |
for line in file: |
| 16 |
# match=re.search("\n", line) # the next few lines are notes and can be ignored |
| 17 |
# if match: |
| 18 |
# line=line.replace("\n","") |
| 19 |
#for x in line: |
| 20 |
# clean = filter(lambda y: y != '\n', x) |
| 21 |
clean = line.rstrip() |
| 22 |
cleanup.append(clean) |
| 23 |
try: |
| 24 |
header = cleanup.index('BSSID, First time seen, Last time seen, channel, Speed, Privacy, Cipher, Authentication, Power, # beacons, # IV, LAN IP, ID-length, ESSID, Key') |
| 25 |
stationStart = cleanup.index('Station MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs') |
| 26 |
del cleanup[header] |
| 27 |
except Exception: |
| 28 |
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") |
| 29 |
sys.exit(1) |
| 30 |
Clients = cleanup[stationStart:] #splits off the clients into their own list |
| 31 |
stationStart = stationStart - 1 #ulgy hack to make sure the heading gets deleted from end of the APs List |
| 32 |
del cleanup[stationStart:]#removed all of the client info leaving only the info on available target AP's in ardump maybe I should create a new list for APs? |
| 33 |
lines = [cleanup,Clients] |
| 34 |
return lines |
| 35 |
def join_write(data,name): |
| 36 |
file = open(name,'a') |
| 37 |
for line in data[0]: |
| 38 |
line=line.rstrip() |
| 39 |
if len(line)>1: |
| 40 |
file.write(line+'\n') |
| 41 |
for line in data [1]: |
| 42 |
if len(line)>1: |
| 43 |
file.write(line+'\n') |
| 44 |
file.close() |
| 45 |
def showBanner(): |
| 46 |
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") |
| 47 |
|
| 48 |
def file_pool(files): |
| 49 |
AP = [] |
| 50 |
Clients = [] |
| 51 |
for file in files: |
| 52 |
ret = raw_lines(file) |
| 53 |
ret = parse_file(ret,file) |
| 54 |
AP.extend(ret[1]) |
| 55 |
Clients.extend(ret[0]) |
| 56 |
lines = [AP,Clients] |
| 57 |
output = sort_file(lines) |
| 58 |
return output |
| 59 |
|
| 60 |
def sort_file(input): |
| 61 |
AP = ['BSSID, First time seen, Last time seen, channel, Speed, Privacy, Cipher, Authentication, Power, # beacons, # IV, LAN IP, ID-length, ESSID, Key'] |
| 62 |
Clients = ['\nStation MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs'] |
| 63 |
Clients.extend(input[0]) |
| 64 |
AP.extend(input[1]) |
| 65 |
output = [AP,Clients] |
| 66 |
return output |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
if __name__ == "__main__": |
| 71 |
if len(sys.argv) <= 1: |
| 72 |
showBanner() |
| 73 |
sys.exit(1) |
| 74 |
|
| 75 |
parser = argparse.ArgumentParser(description="A support tool for airgraph-ng that allows you to join the airodump output files.") |
| 76 |
parser.add_argument("-o", "--output", dest="output",nargs=1, help="output file to write to") |
| 77 |
parser.add_argument("-i", "--file", dest="filename", nargs="*" ,help="Input files to read data from requires at least two arguments") |
| 78 |
|
| 79 |
args = parser.parse_args() |
| 80 |
# we need this manual check because argparse does not support requiring 2 or more nargs |
| 81 |
# the closest we could do is nargs="+" which means 1 or more |
| 82 |
if len(args.filename) < 2: |
| 83 |
parser.print_usage() |
| 84 |
print("airodump-join: error: argument -i/--file: expected at least two arguments") |
| 85 |
sys.exit(1) |
| 86 |
filenames = tuple(args.filename) |
| 87 |
outfile = args.output[0] |
| 88 |
if outfile == None: |
| 89 |
print("You must provide a file name to write out to. IE... -o foo.csv\n") |
| 90 |
showBanner() |
| 91 |
sys.exit(1) |
| 92 |
elif filenames == None: |
| 93 |
print("You must provide at least two file names to join. IE... -i foo1.csv foo2.csv\n") |
| 94 |
showBanner() |
| 95 |
sys.exit(1) |
| 96 |
return_var = file_pool(filenames) |
| 97 |
return_var = join_write(return_var,outfile) |
| 98 |
|
| 99 |
|