问题描述
我需要您帮助处理nmap脚本并将输出打印到csv文件中.当我运行脚本并使用 print(nm.csv())
完成脚本时,显示了以下结果,这是我想要的第一名:
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 want first place:
host;hostname;hostname_type;protocol;port;name;state;product;extrainfo;reason;version;conf;cpe
82.214.228.176;176.228.214.82.in-addr.arpa;PTR;tcp;21;ftp;open;;;syn-ack;;3;
82.214.228.176;176.228.214.82.in-addr.arpa;PTR;tcp;22;ssh;open;;;syn-ack;;3;
82.214.228.176;176.228.214.82.in-addr.arpa;PTR;tcp;53;domain;open;;;syn-ack;;3;
82.214.228.176;176.228.214.82.in-addr.arpa;PTR;tcp;80;http;open;;;syn-ack;;3;
但是我的问题是如何重定向此文件,或者如何在我运行脚本的路径或路径中的同一目录上创建csv文件.预先感谢!
But my question is how to get this redirected or to create a csv file on the same Directory from where I run the script or maybe in a path.Thanks in advance!
推荐答案
您可以声明一个类似这样的函数
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())
编辑:还记得 import sys
如果您决定使用参数,我也建议您使用argparse .
I also would suggest you, if you decide to use arguments, use a module like argparse.
这篇关于nmap和print(nm.csv())帮助需要打印出到csv.file的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!