Skip to content
Snippets Groups Projects
Commit c45cba66 authored by Degen, Bernhard (UT-EEMCS)'s avatar Degen, Bernhard (UT-EEMCS)
Browse files

Implement csv output with option to unroll subnets

parent 5a885dc5
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import distutils.spawn
import os
import sys
import time
from ipaddress import IPv4Network
#
#
......@@ -26,6 +27,8 @@ else:
dr_default = os.path.join(os.getcwd(),'data')
act_choices = ['list','text','pmap','csv','none']
parser = argparse.ArgumentParser(description = 'Process acknowledged scanner data')
parser.add_argument('-u', '--unroll', default=False, action='store_true',
help='Adds all IP addresses in a subnet as separate entries')
parser.add_argument('-d', '--dataroot', default = dr_default,
help='Specifies the data directory; defaults to %s' %(dr_default))
parser.add_argument('-f', '--filter', action='append',
......@@ -178,14 +181,27 @@ def act_output_pmap_text(tags, metadata, dataroot):
result.append("%-20s %s" % (j, i))
return result
def act_output_csv():
def act_output_csv(tags, dataroot, unroll):
"""
act_output_csv(tags, metadata) -> string
outputs the contents of the tagged directories as a csv file with the
organization and the ip.
"""
return
result = ["ip,org"]
for i in tags:
fn = os.path.join(dataroot, i, 'ips.txt')
ip_filedata = load_ip_file(fn)
if ip_filedata is not None:
for j in ip_filedata:
# Check to see if the line specifies a subnet (has a '/').
# If not, add all addresses within the subnet
if unroll and j.find('/') != -1:
for ip in IPv4Network(j):
result.append("%s,%s" % (ip, i))
else:
result.append("%s,%s" % (j, i))
return result
if __name__ == '__main__':
startup(args)
......@@ -207,5 +223,9 @@ if __name__ == '__main__':
results = act_output_pmap_text(targets, org_data, args.dataroot)
for i in results:
print(i)
elif args.action == 'csv':
results = act_output_csv(targets, args.dataroot, args.unroll)
for i in results:
print(i)
sys.exit(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment