1+ # @author:九世
2+ # @time:2019/6/5
3+ # @file:fw.py
4+
5+
6+ from gevent import monkey ;monkey .patch_all ()
7+ import requests
8+ import os
9+ import gevent
10+ from multiprocessing import Process
11+ from configparser import ConfigParser
12+ import re
13+
14+ banner = '''
15+
16+ _______ __ ________
17+ | ___|.-----.|__| | | |.---.-.-----.-----.
18+ | ___|| -__|| | | | || _ | | _ |
19+ |___| |_____||__|________||___._|__|__|___ |
20+ |_____|
21+ '''
22+ print (banner )
23+
24+ black_list = []
25+ bai_list = []
26+ dept = []
27+ js = []
28+ hei = []
29+ guol = []
30+ config = {}
31+
32+ class Fw :
33+ def __init__ (self ,path ,path2 ,path3 ,PATTERN_URl ):
34+ self .path = path
35+ self .path2 = path2
36+ self .path3 = path3
37+ self .PATTERN_URl = PATTERN_URl
38+
39+ def file_pd (self ):
40+ if os .path .exists (path = self .path ) and os .path .exists (path = self .path2 ) and os .path .exists (path = self .path3 ):
41+ print ('[+] 找到配置文件:{}' .format (self .path ))
42+ print ('[+] 找到黑名单文件:{}' .format (self .path2 ))
43+ print ('[+] 找到ini配置文件:{}' .format (self .path3 ))
44+ dk = open (self .path ,'r' ,encoding = 'utf-8' )
45+ for d in dk .readlines ():
46+ qc = "" .join (d .split ('\n ' ))
47+ bai_list .append (qc )
48+
49+ dk2 = open (self .path2 ,'r' ,encoding = 'utf-8' )
50+ for d in dk2 .readlines ():
51+ qc = "" .join (d .split ('\n ' ))
52+ black_list .append (qc )
53+
54+ cf = ConfigParser ()
55+ cf .read (self .path3 )
56+ config ['xc_size' ]= cf .get ('config' ,'calc_xc' )
57+ config ['search_filter' ]= cf .get ('config' ,'gol' )
58+ config ['search' ]= cf .get ('config' ,'search' )
59+ config ['id' ]= cf .get ('config' ,'id' )
60+ try :
61+ self .respone (config ['search' ])
62+ except Exception as r :
63+ print (r )
64+ else :
65+ print ('[-] 配置文件找不到或黑名单或ini配置文件找不到....' )
66+ exit ()
67+
68+ def respone (self ,url ):
69+ headers = {'user-agent' :'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36' }
70+ try :
71+ rqt = requests .get (url = url ,headers = headers )
72+ if rqt .status_code == 200 and rqt .text != '' :
73+ if rqt .url not in hei :
74+ for g in black_list :
75+ if g in rqt .text :
76+ print ('黑名单匹配:{} url:{}' .format (g , rqt .url ))
77+ print ('黑名单匹配:{} url:{}' .format (g ,rqt .url ),file = open ('save/save.txt' ,'a' ,encoding = 'utf-8' ))
78+ hei .append (rqt .url )
79+
80+ if rqt .url not in hei and rqt .url not in guol :
81+ print ('存活url:{}' .format (rqt .url ))
82+ print ('存活url:{}' .format (rqt .url ),file = open ('save/save.txt' ,'a' ,encoding = 'utf-8' ))
83+ guol .append (rqt .url )
84+
85+ for b in bai_list :
86+ if b in rqt .text :
87+ print ('白名单匹配:{} url:{}' .format (b ,rqt .url ))
88+ print ('白名单匹配:{} url:{}' .format (b , rqt .url ),file = open ('save/save.txt' ,'a' ,encoding = 'utf-8' ))
89+
90+
91+ zz = re .findall (self .PATTERN_URl ,rqt .text )
92+ for z in zz :
93+ if config ['search_filter' ] in z :
94+ if z not in dept :
95+ dept .append (z )
96+
97+
98+ if int (config ['id' ])== 1 :
99+ reg = []
100+ calc = 0
101+ for d in dept :
102+ if calc == int (config ['xc_size' ]):
103+ p = Process (target = self .xc ,args = (reg ,))
104+ p .start ()
105+ reg .clear ()
106+ calc = 0
107+ reg .append (d )
108+ calc += 1
109+
110+ if len (reg )> 0 :
111+ p = Process (target = self .xc , args = (reg ,))
112+ p .start ()
113+ else :
114+ for d in dept :
115+ self .respone (d )
116+ except Exception as r :
117+ print (r )
118+
119+ def xc (self ,rg ):
120+ rb = []
121+ for r in rg :
122+ rb .append (gevent .spawn (self .respone ,r ))
123+
124+ gevent .joinall (rb )
125+
126+ if __name__ == '__main__' :
127+ path = 'conf/config.txt'
128+ path2 = 'conf/black.txt'
129+ path3 = 'conf/config.ini'
130+ PATTERN_URl = '<a.*href=\" (https?://.*?)[\" |\' ].*'
131+ obj = Fw (path = path ,path2 = path2 ,path3 = path3 ,PATTERN_URl = PATTERN_URl )
132+ obj .file_pd ()
0 commit comments