国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

掃描網站服務器真實IP的小腳本

2019-11-14 17:01:05
字體:
來源:轉載
供稿:網友
 1 #!/usr/bin/env python 2 # -*- coding: gbk -*- 3 # -*- coding: utf_8 -*- 4 # Date: 2015年9月11日 5 # Author:蔚藍行 6 # 博客 http://www.survivalescaperooms.com/duanv/ 7  8 import requests 9 import threading10 import Levenshtein11 import re12 13 def scan(original_r,cip,ip_begin,original_match,header):14     ip=cip+str(ip_begin)15     try:16         r=requests.get('http://'+ip,headers=header,timeout=1)17     except Exception:18         pass19     else:20         if(r.status_code==original_r.status_code):21             if r.content==original_r.content:22                 PRint '---everything is match!---/n'+ip+'/n--------------------------/n/n/n',23             else:24                 if Levenshtein.ratio(r.text,original_r.text)>0.8: 25                     match=re.search(r"<title>(.*?)</title>",r.content)26                     try:27                         if match==original_match or match.group()==original_match.group():28                             print '--matches>0.8-same title--/n'+ip+'/n--------------------------/n/n/n',29                         else:30                             print '--matches>0.8-diff title--/n'+ip+'/n--------------------------/n/n/n',31                     except Exception:32                         if match==None:33                             #掃描網頁無標題34                             print '-matches>0.8-none title-s-/n'+ip+'/n--------------------------/n/n/n',35                         else:36                             #原始網頁無標題37                             print '-matches>0.8-none title-o-/n'+ip+'/n--------------------------/n/n/n',38 39 def loop(original_r,cip,original_match,header):40     global ip_begin,ip_end,mutex41     while 1:42         mutex.acquire()43         if ip_begin > ip_end:44             mutex.release()45             break46         ip=ip_begin47         ip_begin += 148         mutex.release()49         scan(original_r,cip,ip,original_match,header)50 51 def start():52     global ip_begin,ip_end,mutex53 54     ip_begin=155     ip_end=25456     mutex=threading.Lock()57 58     cip='180.97.33.'59     address='www.baidu.com'60     61     #cip='220.181.136.'62     #address='www.219.me'63     64     header={"host":address,"Accept-Encoding":"identity","User-Agent":""}65     r=requests.get('http://'+address,headers=header)66     67     original_match=re.search(r"<title>(.*?)</title>",r.content)68     69     threads=[]70     for i in range(254):71         threads.append(threading.Thread(target=loop,args=(r,cip,original_match,header)))72     for t in threads:73         t.start()74 75 if __name__ == '__main__':76     start()

 1,由于是多線程,輸出時如果用print xxx會出現因線程搶占而造成的輸出亂序,改用print xxx+‘/n’,可以不用線程鎖并解決這個問題

 2,掃描網段時請求頭加上host:domain_name,可以解決單一IP對應多域名的問題

 3,發送請求時將UA頭置空,可以防止某些網站服務器返回內容過大和不完全相同的問題,提高效率。比如請求百度,有UA頭情況下返回的頁面內容相當大,而且不同IP返回內容有細微差別,腳本就會進行相似度比較,耗時巨大,如果置空UA頭,請求響應內容就比較小,而且不同IP返回內容相同


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇江市| 道真| 改则县| 安义县| 阜阳市| 新丰县| 宣武区| 宜城市| 汝州市| 交口县| 武乡县| 惠水县| 丽水市| 称多县| 万年县| 闽侯县| 丽水市| 称多县| 阜阳市| 增城市| 伊宁县| 南涧| 德化县| 罗山县| 渑池县| 罗山县| 三明市| 平陆县| 昭苏县| 深圳市| 桦川县| 双城市| 巍山| 涪陵区| 喀喇沁旗| 河东区| 乌兰浩特市| 宁德市| 平江县| 乡城县| 白银市|