Python3.4.3 Nmap:带有操作系统检测的主机发现

Python3.4.3 Nmap:带有操作系统检测的主机发现,python,python-3.x,scanning,nmap,Python,Python 3.x,Scanning,Nmap,正在尝试使用python nmap模块运行此主机发现: (我不知道如何打印主机名,因为几乎没有关于如何使用它的文档)。 我希望能够看到网络上每个设备的每个操作系统 import nmap nm = nmap.PortScanner() nm.scan(hosts='192.168.2.1/24', arguments='-sS -O') for host in nm.all_hosts(): #print the host and the Operating system 如果你知道

正在尝试使用python nmap模块运行此主机发现: (我不知道如何打印主机名,因为几乎没有关于如何使用它的文档)。 我希望能够看到网络上每个设备的每个操作系统

import nmap
nm = nmap.PortScanner()

nm.scan(hosts='192.168.2.1/24', arguments='-sS -O')
for host in nm.all_hosts():
    #print the host and the Operating system
如果你知道一个关于如何使用PythonNMAP的好教程,请告诉我! 我在mac 10.10.5上运行,我知道如何使用nmap。 如果您知道如何打印主机发现和其他有用的标记,请在此处帮助我=)
在python 3.4.3上运行。所有主机返回一个字符串列表(ip地址)

只需打印
host
即可获得主机地址

要获取操作系统信息,请使用
nm[host]['osclass']

for host in nm.all_hosts():
    print(host)
    print(nm[host].get('osclass', 'unknown'))
    # {'vendor': 'Linux', 'accuracy': '100', 'type': 'general purpose',
    #  'osfamily': 'Linux', 'osgen': '3.X'}

nmap.PortScanner.all_hosts
返回字符串列表(ip地址)

只需打印
host
即可获得主机地址

要获取操作系统信息,请使用
nm[host]['osclass']

for host in nm.all_hosts():
    print(host)
    print(nm[host].get('osclass', 'unknown'))
    # {'vendor': 'Linux', 'accuracy': '100', 'type': 'general purpose',
    #  'osfamily': 'Linux', 'osgen': '3.X'}

我现在正在尝试,你能告诉我你是怎么找到这些信息的吗?我试图找到一些文档,但xael.org并没有提供很好的信息…@bob,我读了这篇文章。在使用示例中,您可以看到
nm.all_hosts()
返回一个
str
列表:
['127.0.0.1']
很抱歉,但我的问题是让每个设备的操作系统(在nmap中为-O)在192.168.2.1下一个设备(192.168.2.108)上运行时,由于此错误回溯而崩溃(最后一次调用):打印文件“okok.py”,第7行(nm[host]['osclass'])KeyError:'osclass'@bob,捕获
KeyError
异常或使用
dict.get
print(nm[host].get('osclass',Unknown'))
。我相应地更新了答案。我正在尝试,你能告诉我你是如何找到这些信息的吗?我试图找到一些文档,但xael.org并没有提供很好的信息…@bob,我阅读了。在用法示例中,你可以看到
nm.all_hosts()
返回一个
str
['127.0.0.1']
很抱歉,我的问题是让每个设备的操作系统(在nmap中是-O)在192.168.2.1下运行,但是当它在下一个设备(192.168.2.108)上运行时,由于这个错误回溯(最后一次调用):文件“okok.py”,第7行,处于打印状态(nm[host]['osclass'))KeyError:'osclass'@bob,捕获
KeyError
异常或使用
dict.get
print(nm[host].get('osclass','Unknown'))
。我相应地更新了答案。