Skip to content Skip to sidebar Skip to footer

Nmap And Print(nm.csv()) Help Needed To Print Out To Csv.file

I need you help with nmap script and printing the output to csv file. When I run the script and finish it with print(nm.csv()) I got the following results displayed which is what I

Solution 1:

You could declare a function like this one

def save_csv_data(nm_csv, path='.'):
    with open(path + '/output.csv', 'w') as output:
        output.write(nm_csv)

then by passing an argument you could specify another path to save the file, or otherwise, use the same directory as the script:

if (len(sys.argv) > 1 and sys.argv[1]):
    save_csv_data(nm.csv(), path=sys.argv[1])
else:
    save_csv_data(nm.csv())

Edit: also remember to import sys

I also would suggest you, if you decide to use arguments, use a module like argparse.

Solution 2:

print (nm.csv(),file=open('a.csv','w'))

Edited:

You can use the print_function to get the print() behaviour from python3 in python2:

from __future__ import print_function

Post a Comment for "Nmap And Print(nm.csv()) Help Needed To Print Out To Csv.file"