Answer the question
In order to leave comments, you need to log in
Python nmap module problem with the script, I can not display the necessary parameters, how to solve?
You need to write a Python script with the nmap module and scan the VM. It is necessary that the script displays the port, service and its version in a column. Example of a valid output: 21 ftp 2.0
. And so they go to the column.
My script is the following:
import nmap3
nmap = nmap3.Nmap()
result = nmap.nmap_version_detection("10.0.0.3")
for i in result["10.0.0.3"]["ports"]:
print(i["portid"], i["service"])
21 {'name': 'ftp', 'product': 'vsftpd', 'version': '2.3.4', 'ostype': 'Unix', 'method': 'probed', 'conf': '10'}
22 {'name': 'ssh', 'product': 'OpenSSH', 'version': '4.7p1 Debian 8ubuntu1', 'extrainfo': 'protocol 2.0', 'ostype': 'Linux', 'method': 'probed', 'conf': '10'}
23 {'name': 'telnet', 'product': 'Linux telnetd', 'ostype': 'Linux', 'method': 'probed', 'conf': '10'}
25 {'name': 'smtp', 'product': 'Postfix smtpd', 'hostname': ' metasploitable.localdomain', 'method': 'probed', 'conf': '10'}
print(i["portid"], i["name"], i["version"])
Traceback (most recent call last):
File "/home/PycharmProjects/nets/./net.py", line 7, in <module>
print(i["portid"], i["name"], i["version"])
KeyError: 'name'
Answer the question
In order to leave comments, you need to log in
like the name parameter is
i["service"]
output , and here is its output as follows:{'name': 'telnet', 'product': 'Linux telnetd', 'ostype': 'Linux', 'method': 'probed', 'conf': '10'}
name
is not in the dictionary i
, but in the i['service']
. So it will be righti['service']['name']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question