PyHacker编写指南引用Nmap模块实现端口扫描器
作者:巡安似海 时间:2023-07-15 14:15:40
引用Nmap库实现扫描功能,本节课比较简单一看就会。
编写环境:Python2.x
编写:
首先安装Nmap程序,并添加环境变量
pip install nmap
pip install python-nmap
调试扫描:
import nmap
def nmapScan(host,port):
nmScan=nmap.PortScanner() #实例化
state = nmScan.scan(host,port) #scan() 方法扫描端口
print state
nmapScan('127.0.0.1','80')
如果想加nmap参数,直接在后面可以加上,第三个参数可选
state = nmScan.scan(host,port,arguments='-O') #scan()
方法扫描端口
实例化后 调用scan方法进行扫描
输出的内容非常详细,我们可以截取我们想要的内容先说一下几个方法
nmScan=nmap.PortScanner() #实例化
nmScan.scan(host,port) #scan() 方法扫描端口
print nmScan.command_line() #输出命令
print nmScan.scaninfo() #返回nmap扫描信息,为字典类型
print nmScan.all_hosts() #返回nmap扫描信息,为列表类型
根据自己需求,输出自己想要的内容
我们这里选择默认的json格式
输出状态:
print state['scan'][host]['tcp'][int(port)]['state']
来源:https://blog.csdn.net/XunanSec/article/details/124753612
标签:PyHacker,Nmap,端口扫描
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Django点赞的实现示例
2022-08-24 20:13:40
![](https://img.aspxhome.com/file/2023/3/118103_0s.png)
一文让你秒懂精通pip并快速体验深度学习应用【建议收藏】
2022-07-08 22:27:56
![](https://img.aspxhome.com/file/2023/7/72927_0s.png)
Python实现8个概率分布公式的方法详解
2022-05-14 08:14:37
![](https://img.aspxhome.com/file/2023/4/79654_0s.png)
Python之二维正态分布采样置信椭圆绘制
2021-04-08 06:39:09
![](https://img.aspxhome.com/file/2023/4/83824_0s.jpg)
WEB打印大全
2023-06-30 14:35:15
FrontPage2002简明教程一:安装与界面
2008-08-17 11:04:00
![](https://img.aspxhome.com/file/UploadPic/200810/17/20081017111313451.jpg)
深入浅析JavaScript中的arguments对象(强力推荐)
2024-04-25 13:12:46
利用python Pandas实现批量拆分Excel与合并Excel
2023-07-02 19:08:23
pytorch tensorboard可视化的使用详解
2022-09-27 01:01:51
![](https://img.aspxhome.com/file/2023/8/95788_0s.png)
java学习指南之字符串与正则表达式
2022-02-23 14:05:50
![](https://img.aspxhome.com/file/2023/0/96820_0s.png)
详解python的变量
2021-01-26 20:44:20
![](https://img.aspxhome.com/file/2023/1/124771_0s.png)
python 基于opencv实现图像增强
2023-03-20 21:04:32
![](https://img.aspxhome.com/file/2023/4/64294_0s.png)
网页设计中怎么将px换成em
2008-04-16 13:50:00
Python3利用SMTP协议发送E-mail电子邮件的方法
2023-10-12 17:39:32
![](https://img.aspxhome.com/file/2023/2/63202_0s.jpg)
Pycharm 如何设置HTML文件自动补全代码或标签
2021-08-12 17:47:15
![](https://img.aspxhome.com/file/2023/3/121473_0s.png)
一文带你吃透什么是PHP中的序列化
2023-06-12 19:44:20
基于javascript实现九宫格大转盘效果
2024-04-17 10:33:13
![](https://img.aspxhome.com/file/2023/4/136234_0s.jpg)
PHP实现获取第一个中文首字母并进行排序的方法
2023-10-30 12:29:08
python异常处理、自定义异常、断言原理与用法分析
2023-06-12 02:36:08
![](https://img.aspxhome.com/file/2023/4/115034_0s.png)
原生Js与jquery的多组处理, 仅展开一个区块的折叠效果
2024-04-17 10:06:48
![](https://img.aspxhome.com/file/2023/2/136382_0s.png)