我有 2 个pickel 文件,其中包含 IP 地址以及与它们相关的端口、aws_tags 和区域信息。这基本上是一个端口扫描器,它有一种在找到新 IP 地址时打印的方法。这是通过用 OLD_pickel_scan 减去 NEW_pickel_scan 来完成的,如下所示:
self.prev_hosts = set()
self.curr_hosts = set()
def new_hosts(self)
result_new_hosts = self.curr_hosts - self.prev_hosts
这工作正常并打印在pickel报告中添加的新IP。
现在我也需要添加该 IP 地址的关联标签和区域。我已经在映射中获得了所需的数据:
mapping = {i[0]:[i[1],i[2]] for i in data}
i[0] 是 IP , i[1] 是标签, i[2] 是区域
所以我正在尝试使用此映射打印标签。
例如,我有另一种方法可以在找到非法端口时打印
def dump_raw(self,mapping):
nmap_report = self.report
for host in nmap_report.hosts:
#print
if len(host.hostnames):
tmp_host = host.hostnames.pop()
else:
tmp_host = host.address
print("Nmap scan report for {0} ({1})".format(tmp_host,host.address))
print("Host is {0}.".format(host.status))
#val = config.get('ports', 'scan_range')
#val_known = config.get('ports','known')
#safe_port = range(*map(int, val.split(',')))
#known_ports = map(int, val_known.split(','))
print(" PORT STATE SERVICE")
for serv in host.services:
if serv.state == "open":
## print ('Illegal Port open :'+str(serv.port) +'/'+str(serv.protocol)+' '+str(serv.service)+', on host=> '+str(host))
print ('Illegal Port open :'+str(serv.port) +'/'+str(serv.protocol)+' '+str(serv.service)+', on host=> '+str(host) + ' Tag =' + (mapping[host.address.strip()][0]) + ' Region =' + str(mapping[host.address.strip()][1]))
这就是我使用映射的方式,有人可以帮助我new_hosts()
吗?
我试过 :
def new_hosts(self,mapping):
"""Return a list of new hosts added in latest scan"""
result_new_hosts = self.curr_hosts - self.prev_hosts
print mapping[result_new_hosts]
它说 : TypeError: unhashable type: 'set'
如果我做类似的事情:
def new_hosts(self,mapping):
"""Return a list of new hosts added in latest scan"""
result_new_hosts = self.curr_hosts - self.prev_hosts
print mapping[result_new_hosts]
nmap_report = self.report
for host in nmap_report.hosts:
for serv in host.services:
print result_new_hosts,mapping[result_new_hosts.address.strip()[0]],mapping[result_new_hosts.address.strip()[1]]
return (result_new_hosts,mapping[result_new_hosts.address.strip()[0]],mapping[result_new_hosts.address.strip()[1]])
这打印:
AttributeError: 'set' object has no attribute 'address'