我有一个libnmap扫描程序脚本,基本上可以通过从AWS收集所有EIP并逐个扫描它们,收集所有EIP的功能如下:
def gather_public_ip():
ACCESS_KEY = config.get('aws','access_key')
SECRET_KEY = config.get('aws','secret_key')
regions = regions = ['us-west-2','eu-central-1','ap-southeast-1']
all_EIP = []
for region in regions:
client = boto3.client('ec2',aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY,region_name=region,)
addresses_dict = client.describe_addresses()
for eip_dict in addresses_dict['Addresses']:
if 'PrivateIpAddress' in eip_dict:
print eip_dict['PublicIp']
all_EIP.append(eip_dict['PublicIp'])
print all_EIP
return all_EIP
这个函数基本上给我一个看起来像
的列表['22.22.124.141', '22.21.149.191', '22.11.132.122', '22.11.227.241', '22.34.28.112', '22.34.211.227', '22.27.21.233', '22.24.199.122', '22.11.113.171', '22.21.11.8', '22.33.31.14', '22.37.19.213', '22.24.121.112', '22.32.121.132', '22.24.21.1', '22.34.72.198']
我调用上述方法的主函数然后将它传递给我的实际扫描仪函数,如下所示:
s = Scanner(config)
# Execute Scan and Generate latest report
net_range = gather_public_ip() # config.get('sources','networks') ## Call DEF
#print type(net_range)
r = s.run(net_range)
s.save() # save to pickle
扫描仪类看起来像:
class Scanner(object):
"""Container for all scan activies"""
def __init__(self,cp):
self.config = cp # read in ConfigParser object to get settings
self.report = None
def gather_targets(self):
"""Gather list of targets based on configured sources"""
pass
def run(self, targets="" ,options="-Pn"):
#start a new nmap scan on localhost with some specific options
syslog.syslog("Scan started")
parsed = None
nmproc = NmapProcess(targets,options)
rc = nmproc.run()
有人可以帮我处理我可以将列表中的值逐个传递给run方法的部分,以便nmap可以处理它,现在它只是空闲
答案 0 :(得分:1)
传递参数的方式看起来不错。但是,您没有任何实际使用结果的代码。
尝试像这样更改Scanner.run
:
class Scanner(object):
...
def run(self, targets="" ,options="-Pn"):
#start a new nmap scan on localhost with some specific options
syslog.syslog("Scan started")
parsed = None
nmproc = NmapProcess(targets,options)
nmproc.run_background()
while nmproc.is_running():
print("Nmap Scan running: ETC: {0} DONE: {1}%".format(nmproc.etc,
nmproc.progress))
sleep(2)
print("rc: {0} output: {1}".format(nmproc.rc, nmproc.summary))
直接来自the docs。