我正在使用 nmap 进行端口扫描功能。但是,我得到这种类型的字符串索引必须是整数的错误。能帮忙指点我哪里出错了吗?
self.txtarea.Clear()
targetServerinput = self.targethost_input.GetValue()
if len(targetServerinput) == 0:
empty_error = wx.MessageDialog(None,"There is no input.\nPlease Try Again.","",wx.OK|wx.ICON_ERROR)
empty_error.ShowModal()
else:
try:
targetServerIP = socket.gethostbyname(targetServerinput)
nm = nmap.PortScanner()
nm.scan(targetServerIP,'1-1024')
nm[targetServerIP]['tcp'].keys()
for host in nm.all_hosts():
print('----------------------------------------------------')
print('Host : %s (%s)' % (host, nm[host].hostname()))
print('State : %s' % nm[host].state())
for proto in nm[host].all_protocols():
print('----------')
lport = nm[host][proto].keys()
lport.sort()
for port in lport:
print('port : %s\tstate : %s' %(port,nm[host][proto][port]['state']))
#targetServerResult = str(targetServerIP)
except socket.gaierror:
name_error = wx.MessageDialog(None,"Name or service not known\nPlease Try Again.","",wx.OK|wx.ICON_ERROR)
name_error.ShowModal()
我收到了这个错误-
Traceback (most recent call last):
File "wxloginv1.py", line 168, in scan_btnClick
print('port : %s\tstate : %s' %(port,nm[host][proto][port]['state']))
TypeError: string indices must be integers