Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sbnsec/e6f5aec34dd84ad92e5f50c44694648b to your computer and use it in GitHub Desktop.
Save sbnsec/e6f5aec34dd84ad92e5f50c44694648b to your computer and use it in GitHub Desktop.
NmaptoCSV parser concatenate the host to get all the port open in one line
# <HOST>,<PORT>,<whatever>
# used as nmaptocsv parser : https://github.com/maaaaz/nmaptocsv/
#
# Takes as input
# toto,value
# toto, value1
# tata, value
# tata value1
#
# gives at output
#
# toto, value-value1
# toto, value-value1
#
import csv
with open('input.txt') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
first_line = next(csv_reader, None)
prev_line = first_line[0]
found_ports = first_line[1]
current_line = first_line[0]
for row in csv_reader:
current_line = row[0]
if prev_line == current_line:
current_line = row[0]
found_ports += "-"+row[1]
else:
print( prev_line + ", " + found_ports )
current_line = row[0]
prev_line = current_line
found_ports = row[1]
print( current_line + ", " + found_ports )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment