#!/usr/bin/env python
# -*- coding: gbk -*-
# -*- coding: utf_8 -*-
# Date: 2015年9月11日
# Author:蔚蓝行
# 博客 http://www.cnblogs.com/duanv/ import requests
import threading
import Levenshtein
import re def scan(original_r,cip,ip_begin,original_match,header):
ip=cip+str(ip_begin)
try:
r=requests.get('http://'+ip,headers=header,timeout=1)
except Exception:
pass
else:
if(r.status_code==original_r.status_code):
if r.content==original_r.content:
print '---everything is match!---\n'+ip+'\n--------------------------\n\n\n',
else:
if Levenshtein.ratio(r.text,original_r.text)>0.8:
match=re.search(r"<title>(.*?)</title>",r.content)
try:
if match==original_match or match.group()==original_match.group():
print '--matches>0.8-same title--\n'+ip+'\n--------------------------\n\n\n',
else:
print '--matches>0.8-diff title--\n'+ip+'\n--------------------------\n\n\n',
except Exception:
if match==None:
#扫描网页无标题
print '-matches>0.8-none title-s-\n'+ip+'\n--------------------------\n\n\n',
else:
#原始网页无标题
print '-matches>0.8-none title-o-\n'+ip+'\n--------------------------\n\n\n', def loop(original_r,cip,original_match,header):
global ip_begin,ip_end,mutex
while 1:
mutex.acquire()
if ip_begin > ip_end:
mutex.release()
break
ip=ip_begin
ip_begin += 1
mutex.release()
scan(original_r,cip,ip,original_match,header) def start():
global ip_begin,ip_end,mutex ip_begin=1
ip_end=254
mutex=threading.Lock() cip='180.97.33.'
address='www.baidu.com' #cip='220.181.136.'
#address='www.219.me' header={"host":address,"Accept-Encoding":"identity","User-Agent":""}
r=requests.get('http://'+address,headers=header) original_match=re.search(r"<title>(.*?)</title>",r.content) threads=[]
for i in range(254):
threads.append(threading.Thread(target=loop,args=(r,cip,original_match,header)))
for t in threads:
t.start() if __name__ == '__main__':
start()

1,由于是多线程,输出时如果用print xxx会出现因线程抢占而造成的输出乱序,改用print xxx+‘\n’,可以不用线程锁并解决这个问题

2,扫描网段时请求头加上host:domain_name,可以解决单一IP对应多域名的问题

3,发送请求时将UA头置空,可以防止某些网站服务器返回内容过大和不完全相同的问题,提高效率。比如请求百度,有UA头情况下返回的页面内容相当大,而且不同IP返回内容有细微差别,脚本就会进行相似度比较,耗时巨大,如果置空UA头,请求响应内容就比较小,而且不同IP返回内容相同

最新文章

  1. Linux下常见的IO模型
  2. ElasticSearch-5.0安装head插件
  3. AngularJs 与Jquery的对比分析,超详细!
  4. Could not load file or assembly &#39;System.Data.SQLite&#39; or one of its dependencies
  5. 常用的正则表达式(例如:匹配中文、匹配html)(转载)
  6. oracle 直接客户端使用
  7. .net的WebForm模拟MVC进行模型绑定,让自己少操劳
  8. 微信开发-Jssdk调用分享实例
  9. PreferenceActivity使用示例
  10. C# 单例模式(Singleton Pattern)(转SuagrMatl)
  11. [SCOI2016]幸运数字
  12. 11 OptionsMenu 菜单
  13. Linux 虚拟网络设备 veth-pair 详解,看这一篇就够了
  14. ELK日志监控平台安装部署简介--Elasticsearch安装部署
  15. Qt之使用CQU库快速开发统一风格界面
  16. poj很好很有层次感(转)
  17. eclipse 把鼠标指针放在错误的语句上 提示快速修正 不见了的解决方法
  18. python处理数据问题详解
  19. ASP.NET Core2.1 你不得不了解的GDPR(Cookie处理) - (转载)
  20. P3232 [HNOI2013]游走 解题报告

热门文章

  1. AbpZero之企业微信---登录(拓展第三方auth授权登录)---第一步:查看AbpZero的auth第三方登录的底层机制
  2. ADO.NET系列之DataAdapter对象
  3. go语言最快最好运用最广的web框架比较(大多数人不了解的特性)
  4. .net core 滑动+点击汉字验证码
  5. NetCore入门篇:(六)Net Core项目使用Controller之一
  6. 1.python的一些规范
  7. sql语句_统计总成绩最高的前2名
  8. 一,PHP会话机制---cookie
  9. 程序猿的日常——JVM内存模型与垃圾回收
  10. activemq消息生产者与消息消费者简单例子