Created
April 8, 2020 15:28
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# <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