Python批量IP端口扫描和指纹识别脚本

本脚本使用Python编写,用于批量IP的端口扫描和指纹识别。扫描结果将会保存在result.txt文件中。

依赖

本脚本需要安装以下Python库:

  • nmap
  • python-nmap
  • python-whois
  • requests

您可以使用以下命令进行安装:

pip install python-nmap python-whois requests

使用方法

  1. 将需要扫描的IP地址写入一个文本文件中,每行一个IP地址。

  2. 运行以下命令:

    python scan.py --file [IP地址文件路径]
    

    示例:

    python scan.py --file ip.txt
    
  3. 扫描结果将会保存在result.txt文件中。

脚本代码

以下为本脚本的代码,您可以按照自己的需求进行修改:

import argparse
import nmap
import whois
import requests

# 解析命令行参数
parser = argparse.ArgumentParser(description='批量IP端口扫描与指纹识别')
parser.add_argument('--file', help='IP地址文件路径')
args = parser.parse_args()

# 读取IP地址列表
with open(args.file) as f:
    ips = [line.strip() for line in f.readlines()]

# 扫描端口和识别指纹
nm = nmap.PortScanner()
with open('result.txt', 'w') as f:
    for ip in ips:
        result = nm.scan(ip, arguments='-sS')
        ports = result['scan'][ip]['tcp'].keys()
        f.write('IP地址: {}
'.format(ip))
        f.write('开放端口: {}
'.format(','.join(str(port) for port in ports)))
        for port in ports:
            try:
                service = nm[host]['tcp'][port]['name']
                product = nm[host]['tcp'][port]['product']
                version = nm[host]['tcp'][port]['version']
                f.write('端口{}: {} {} {}
'.format(port, service, product, version))
            except:
                pass
        try:
            w = whois.whois(ip)
            f.write('域名信息: {}
'.format(w.domain_name))
        except:
            pass
        try:
            r = requests.get('http://{}/'.format(ip))
            f.write('Web服务: {}
'.format(r.headers['Server']))
        except:
            pass

print('扫描完成!请查看result.txt文件。')
Python批量IP端口扫描和指纹识别脚本

原文地址: https://www.cveoy.top/t/topic/lmM0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录