官网 https://pypi.org/project/python-nmap/

>>> import nmap
>>> nm = nmap.PortScannerScanner()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'nmap' has no attribute 'PortScannerScanner'
>>> nm = nmap.PortScanner()
>>> nm.scan('127.0.0.1','22-443')
{'nmap': {'command_line': 'nmap -oX - -p 22-443 -sV 127.0.0.1', 'scaninfo': {'tcp': {'method': 'syn', 'services': '22-443'}}, 'scanstats': {'timestr': 'Wed Oct 23 17:25:01 2019', 'elapsed': '6.20', 'uphosts': '1', 'downhosts': '0', 'totalhosts': '1'}}, 'scan': {'127.0.0.1': {'hostnames': [{'name': 'localhost', 'type': 'PTR'}], 'addresses': {'ipv4': '127.0.0.1'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'localhost-response'}, 'tcp': {22: {'state': 'open', 'reason': 'syn-ack', 'name': 'ssh', 'product': 'OpenSSH', 'version': '7.4', 'extrainfo': 'protocol 2.0', 'conf': '10', 'cpe': 'cpe:/a:openbsd:openssh:7.4'}, 25: {'state': 'open', 'reason': 'syn-ack', 'name': 'smtp', 'product': 'Postfix smtpd', 'version': '', 'extrainfo': '', 'conf': '10', 'cpe': 'cpe:/a:postfix:postfix'}, 111: {'state': 'open', 'reason': 'syn-ack', 'name': 'rpcbind', 'product': '', 'version': '2-4', 'extrainfo': 'RPC #100000', 'conf': '10', 'cpe': ''}}}}}
>>> nm.command_line
<bound method PortScanner.command_line of <nmap.nmap.PortScanner object at 0x2ba54ca28978>>
>>> nm.command_line()
'nmap -oX - -p 22-443 -sV 127.0.0.1'
>>> nm.scaninfo
<bound method PortScanner.scaninfo of <nmap.nmap.PortScanner object at 0x2ba54ca28978>>
>>> nm.scaninfo()
{'tcp': {'method': 'syn', 'services': '22-443'}}
>>> nm.scaninfo()['tcp']
{'method': 'syn', 'services': '22-443'}
>>> nm.scaninfo()['tcp']['method']
'syn'
>>> nm.all_hosts()
['127.0.0.1']
>>> nm['127.0.0.1'].hostname()
'localhost'
>>> nm['127.0.0.1'].hostnames()
[{'name': 'localhost', 'type': 'PTR'}]
>>> nm.scan(hosts="192.168.1.0/24",arguments="-n -sP -PE")
{'nmap': {'command_line': 'nmap -oX - -n -sP -PE 192.168.1.0/24', 'scaninfo': {}, 'scanstats': {'timestr': 'Wed Oct 23 17:29:13 2019', 'elapsed': '1.07', 'uphosts': '15', 'downhosts': '241', 'totalhosts': '256'}}, 'scan': {'192.168.1.1': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.1'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.43': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.43'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.50': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.50'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.72': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.72'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.74': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.74'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.77': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.77'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.80': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.80'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.103': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.103'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.203': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.203'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.204': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.204'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.211': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.211'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.222': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.222'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.243': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.243'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.245': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.245'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}, '192.168.1.255': {'hostnames': [{'name': '', 'type': ''}], 'addresses': {'ipv4': '192.168.1.255'}, 'vendor': {}, 'status': {'state': 'up', 'reason': 'echo-reply'}}}}
>>> nm.all_hosts()
['192.168.1.1', '192.168.1.103', '192.168.1.203', '192.168.1.204', '192.168.1.211', '192.168.1.222', '192.168.1.243', '192.168.1.245', '192.168.1.255', '192.168.1.43', '192.168.1.50', '192.168.1.72', '192.168.1.74', '192.168.1.77', '192.168.1.80']

python 使用nmap 模块的更多相关文章

  1. 端口扫描器--利用python的nmap模块

    安装nmap模块挺麻烦的,搞了半天 不仅要安装pip install nmap 还要sudo apt install nmap 给出代码,没有设多线程,有点慢,注意端口的类型转换,搞了很久 #!/us ...

  2. python(nmap模块、多线程模块)

    http://xael.org/pages/python-nmap-en.html       nmap模块 http://www.tutorialspoint.com/python/python_m ...

  3. 7.python实现高效端口扫描器之nmap模块

    对于端口扫描,使用的最多的就是nmap这个工具,不想python已经强大到,提供了nmap这个扫描端口的模块. 本片文章主要介绍nmap模块的两个常用类: PortScanner()类,实现一个nma ...

  4. python nmap模块使用进行主机探测(ICMP)

    终于审核通过了......第一次用博客,想记录自己的学习情况,分享知识. 废话不多说,第一篇blog,大牛请轻喷. 资产清点首先需要进行主机探测,将存活主机统计下来再进行进一步的指纹识别及端口探测.若 ...

  5. python nmap模块 端口探测

    今天添加端口探测功能,主要实现方式是通过nmap模块调用,扫描1-65535端口.上一篇中已经将UP的PC机全部获取到,这里直接从已知在线的PC中进行端口扫描就可以了,会节省很多时间. 代码如下,还是 ...

  6. Python调用nmap扫描网段主机信息生成xml

    #!/usr/bin/env python # -*- coding: utf_8 -*- # Date: 2015年10月23日 # Author:蔚蓝行 # 博客 http://www.cnblo ...

  7. 7.安装pycharm----导入Nmap模块----netcat反向shell----metasploitable靶机环境

    安装pycharm www.jetbrains.com/pycharm/ tar -zxvf p补全 ls cd p补全 ls cd bin ls ./pycharm.sh 新建项目 pythonRo ...

  8. python之platform模块

    python之platform模块 ^_^第三个模块从天而降喽!! 函数列表 platform.system() 获取操作系统类型,windows.linux等 platform.platform() ...

  9. python之OS模块详解

    python之OS模块详解 ^_^,步入第二个模块世界----->OS 常见函数列表 os.sep:取代操作系统特定的路径分隔符 os.name:指示你正在使用的工作平台.比如对于Windows ...

随机推荐

  1. Nginx 极简入门教程!

    上篇文章和大家聊了 Spring Session 实现 Session 共享的问题,有的小伙伴看了后表示对 Nginx 还是很懵,因此有了这篇文章,算是一个 Nginx 扫盲入门吧! 基本介绍 Ngi ...

  2. R数据挖掘 第一篇:聚类分析(划分)

    聚类是把一个数据集划分成多个子集的过程,每一个子集称作一个簇(Cluster),聚类使得簇内的对象具有很高的相似性,但与其他簇中的对象很不相似,由聚类分析产生的簇的集合称作一个聚类.在相同的数据集上, ...

  3. python排序 基数排序

    算法思想 基数排序通过按位比较(一般从最低位开始)将元素按照最低位的数放到10个桶中,当所有的元素都这样被处理一次后,在按从0到9的顺序将每个桶的元素再取出来(不关注其他位的,只关注当前位的)这样就完 ...

  4. 2-Consul简介

    Consul 是什么 Consul 是一个支持多数据中心分布式高可用的服务发现和配置共享的服务软件,由 HashiCorp 公司用 Go 语言开发, 基于 Mozilla Public License ...

  5. 常用的python内置模块

    1.time模块: time模块是普通的时间模块 在python的三种时间表现形式: 1.时间戳: 给电脑看的. - 自1970-01-01 00:00:00到当前时间,按秒计算,计算了多少秒. 2. ...

  6. P3028 汽水机(差分)

    题目 P3028 [USACO10OCT]汽水机Soda Machine 解析 差分,看到\(a[i]\leq 1e9\),离散化一下,在\(l\)处\(+1\),\(r+1\)处\(-1\),这样就 ...

  7. Java自学-I/O Stream流

    Java的流 Stream 什么是流(Stream),流就是一系列的数据 步骤 1 : 什么是流 当不同的介质之间有数据交互的时候,JAVA就使用流来实现. 数据源可以是文件,还可以是数据库,网络甚至 ...

  8. Spring MVC处理参数Convert

    Springmvc.xml 配置convert,xml中配置多个相同的泛型时,xml里配置的convert会从上到下挨个执行. <!-- 配置注解驱动,并配置convert --> < ...

  9. Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果

    一:如何自定义TextView实现滚动效果 继承TextView基类 重写构造方法 修改isFocused()方法,获取焦点. /* * Copyright (C) 2015 The Android ...

  10. Python3和HTMLTestRunner生成html测试报告

    1.测试环境: Python3.5+unittest+HTMLTestRunner 2.下载HTMLTestRunner.py文件 下载地址 http://tungwaiyip.info/softwa ...