I'm new in python And I have a problem that I haven't been able to solve for a couple of days and I don't understand what the error is at all. I am writing a program based on the Nmap program and the library of the same name, the functionality of which is to scan open ports of some list of ip addresses. I'm trying to implement this through a dictionary, when I did everything on a static variable of ports, everything was fine, but when the program scans ports for each address, such an error is issued on the second iteration of the scan cycle.
'dict' object is not callable
File "C:\Users\Duoksi\Desktop\codes\python\NmapScanPy\test.py", line 47, in ScanPorts
result = nmap.scan_command(ip, arg = attribute)
Below is the function code. You can also install the library with this command: pip install python3-nmap
import nmap3
def Portscan():
nmap = nmap3.Nmap()
attribute = "-p "
port = input("Enter ports(ex. 80,443)\n")
attribute += str(port)
ipport = dict()
IPrange = ['93.187.72.82', '93.187.72.94', '93.187.72.115', '93.187.72.241', '93.187.72.19', '93.187.72.59', '93.187.72.208',
'93.187.72.179', '93.187.72.24', '93.187.72.137', '93.187.72.136', '93.187.72.130']
for ip in IPrange:
result = nmap.scan_command(ip, arg = attribute)
resultclean = re.findall('\'protocol\': \'\w+\', \'portid\': \'\w+\', \'state\': \'\w+\'', str(result))
for res in resultclean:
ipport.setdefault(ip, []).append(res)
return ipport
Output that i expect: pic of output