python 实现的IP 存活扫描脚本


Posted in Python onDecember 10, 2020

下载地址

ActiveOrNot

用于处理 oneforall 等子域名扫描工具的结果去重 + 主机存活扫描

参数

-f --file  指定存放ip或子域名的文件,默认 ip.txt
-t --thread  设置线程数,默认 50

python3 ActiveOrNot.py -f ip.txt -t 12

具体代码 ActiveOrNot.py

from threading import Thread
from queue import Queue
import requests
from time import time
import argparse

headers = {
 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
}


def ping(url, new_ip):
 url = url.strip()
 if (not url.startswith('http://')) and (not url.startswith('https://')):
  url = 'http://' + url
 try:
  req = requests.get(url, headers=headers, timeout=2)
  new_ip.put(url + ' -- ' + str(req.status_code))
  print("%s 存活" % url)
 except:
  print("%s 不存活" % url)


def new_list(file):
 with open(file, 'r') as f:
  new_ip = []
  ip_list = f.readlines()
  for ip in ip_list:
   ip = ip.strip().replace('http://', '').replace('https://', '')
   if ip:
    if not (ip in new_ip):
     new_ip.append(ip)
  return new_ip


def main(file, th):
 begin_time = time()
 new_ip = Queue()
 ip_list = new_list(file)
 j = 0
 length = len(ip_list)
 while j < length:
  threads = []
  for i in range(th):
   t = Thread(target=ping, args=(ip_list[j], new_ip))
   t.start()
   threads.append(t)
   j += 1
   if j == length:
    break
  for thread in threads:
   thread.join()
 with open('NewIP.txt', 'a+') as nf:
  while not new_ip.empty():
   nf.write(new_ip.get()+'\n')
 end_time = time()
 run_time = end_time - begin_time
 print("总共耗时 %s 秒"% run_time)


if __name__ == '__main__':
 parser = argparse.ArgumentParser(description='url active scan')
 parser.add_argument("-f", "--file", help="指定文件", default='ip.txt')
 parser.add_argument("-t", "--thread", help="设置线程", default=50)
 args = parser.parse_args()
 file = args.file
 th = args.thread
 main(file, th)

以上就是python 实现的IP 存活扫描脚本的详细内容,更多关于python ip存活扫描的资料请关注三水点靠木其它相关文章!

Python 相关文章推荐
python判断windows隐藏文件的方法
Mar 21 Python
Python中is与==判断的区别
Mar 28 Python
python 全文检索引擎详解
Apr 25 Python
Python用csv写入文件_消除空余行的方法
Jul 06 Python
Python3标准库总结
Feb 19 Python
Python之Numpy的超实用基础详细教程
Oct 23 Python
Pytorch 中retain_graph的用法详解
Jan 07 Python
解决springboot yml配置 logging.level 报错问题
Feb 21 Python
快速解决jupyter启动卡死的问题
Apr 10 Python
超全Python图像处理讲解(多模块实现)
Apr 13 Python
解决pip install psycopg2出错问题
Jul 09 Python
Python爬虫防封ip的一些技巧
Aug 06 Python
class类在python中获取金融数据的实例方法
Dec 10 #Python
Python制作简单的剪刀石头布游戏
Dec 10 #Python
python给list排序的简单方法
Dec 10 #Python
详解java调用python的几种用法(看这篇就够了)
Dec 10 #Python
Python利用imshow制作自定义渐变填充柱状图(colorbar)
Dec 10 #Python
详解Python GUI编程之PyQt5入门到实战
Dec 10 #Python
python 实现ping测试延迟的两种方法
Dec 10 #Python
You might like
《五等分的花嫁》漫画完结!2020年10月第2期TV动画制作组换血!
2020/03/06 日漫
浅谈php和.net的区别
2014/09/28 PHP
php实现图片上传并进行替换操作
2016/03/15 PHP
php curl获取到json对象并转成数组array的方法
2018/05/31 PHP
关于Yii2框架跑脚本时内存泄漏问题的分析与解决
2019/12/01 PHP
由Javascript实现的页面日历
2011/11/04 Javascript
jQuery插件jQuery-JSONP开发ajax调用使用注意事项
2013/11/22 Javascript
jQuery中:header选择器用法实例
2014/12/29 Javascript
jquery中实现时间戳与日期相互转换
2016/04/12 Javascript
JavaScript中的跨浏览器事件操作的基本方法整理
2016/05/20 Javascript
分享JS数组求和与求最大值的方法
2016/08/11 Javascript
javascript帧动画(实例讲解)
2017/09/02 Javascript
vue项目使用$router.go(-1)返回时刷新原来的界面操作
2020/07/26 Javascript
vue监听键盘事件的相关总结
2021/01/29 Vue.js
操作Windows注册表的简单的Python程序制作教程
2015/04/07 Python
1 行 Python 代码快速实现 FTP 服务器
2018/01/25 Python
PyQt QCombobox设置行高的方法
2019/06/20 Python
Python的垃圾回收机制详解
2019/08/28 Python
PyTorch 随机数生成占用 CPU 过高的解决方法
2020/01/13 Python
python GUI库图形界面开发之PyQt5访问系统剪切板QClipboard类详细使用方法与实例
2020/02/27 Python
Python多线程通信queue队列用法实例分析
2020/03/24 Python
Python类的继承super相关原理解析
2020/10/22 Python
使用Python+Appuim 清理微信的方法
2021/01/26 Python
印度最大的网上花店:Ferns N Petals(鲜花、礼品和蛋糕)
2017/10/16 全球购物
菲律宾购物网站:Lazada菲律宾
2018/04/05 全球购物
匈牙利最大的健身制造商和销售商:inSPORTline
2018/10/30 全球购物
美赞臣营养马来西亚旗舰店:Enfagrow马来西亚
2019/07/26 全球购物
英国顶级足球鞋的领先零售商:Lovell Soccer
2019/08/27 全球购物
主题酒店策划书
2014/01/28 职场文书
学生感冒英文请假条
2014/02/04 职场文书
家长会标语
2014/06/24 职场文书
2014年国庆节庆祝建国65周年比赛演讲稿
2014/09/21 职场文书
2019财务管理制度最新范本!
2019/07/09 职场文书
python - timeit 时间模块
2021/04/06 Python
Python内置数据类型中的集合详解
2022/03/18 Python
Typescript类型系统FLOW静态检查基本规范
2022/05/25 Javascript