├── README.md └── online-checker.py /README.md: -------------------------------------------------------------------------------- 1 | # online-checker 2 | An adaptive URL online checker for python2 and python3 3 | 基于python实现的批量URL在线存活检测工具 4 | - 无缝自适应支持python2和python3 5 | - 采用python默认模块,无需安装任何第三方模块即可使用 6 | - 多线程快速检测 7 | 8 | ## Usage 9 | ``` 10 | 11 | ___ _ _ ___ _ _ 12 | /___\_ __ | (_)_ __ ___ / __\ |__ ___ ___| | _____ _ __ 13 | // // '_ \| | | '_ \ / _ \ / / | '_ \ / _ \/ __| |/ / _ \ '__| 14 | / \_//| | | | | | | | | __/ / /___| | | | __/ (__| < __/ | 15 | \___/ |_| |_|_|_|_| |_|\___| \____/|_| |_|\___|\___|_|\_\___|_| 16 | 17 | An adaptive URL online checker for python2 and python3 18 | 19 | Usage: python online-checker.py filename 20 | ``` 21 | 22 | **本软件只做初步信息探测,无攻击性行为。请使用者遵守《中华人民共和国网络安全法》,勿将online-checker用于非授权的测试,本人不负任何连带法律责任。** -------------------------------------------------------------------------------- /online-checker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding:utf8 -*- 3 | import threading 4 | import sys 5 | import re 6 | 7 | is_py2 = (sys.version_info[0] == 2) 8 | if is_py2: 9 | import Queue 10 | import urllib2 11 | workQueue = Queue.Queue() 12 | else: 13 | import queue 14 | import urllib.request 15 | workQueue = queue.Queue() 16 | 17 | output_file_200=open('checked_200.txt','a+') 18 | output_file_302=open('checked_302.txt','a+') 19 | error_file=open('error.txt','a+') 20 | 21 | queueLock = threading.Lock() 22 | thread_num = 50 23 | threads = [] 24 | 25 | 26 | class MyThread (threading.Thread): 27 | def __init__(self, Queue,id): 28 | threading.Thread.__init__(self) 29 | self.q = Queue 30 | 31 | def run(self): 32 | while not workQueue.empty(): 33 | check_online(self.q.get()) 34 | 35 | 36 | 37 | def check_online(url): 38 | try: 39 | headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'} 40 | if is_py2: 41 | request = urllib2.Request(url=url, headers=headers) 42 | html = urllib2.urlopen(request) 43 | else: 44 | request = urllib.request.Request(url=url, headers=headers) 45 | html= urllib.request.urlopen(request) 46 | status_code=html.code 47 | if status_code == 200: 48 | queueLock.acquire() 49 | output_file_200.write(url+'\n') 50 | output_file_200.flush() 51 | print_color("[+] %s 200 ok" % url,'blue') 52 | queueLock.release() 53 | elif status_code == 302: 54 | queueLock.acquire() 55 | output_file_302.write(url+'\n') 56 | output_file_200.flush() 57 | print_color("[+] %s 302 ok" % url,'gray') 58 | queueLock.release() 59 | except Exception as e: 60 | error_file.write('%s %s\n'%(url,str(e))) 61 | error_file.flush() 62 | print(str(e)) 63 | 64 | def print_color(data,color="white"): 65 | if color == 'green': print('\033[1;32m%s\033[1;m' % data) 66 | elif color == 'blue' : print('\033[1;34m%s\033[1;m' % data) 67 | elif color=='gray' : print('\033[1;30m%s\033[1;m' % data) 68 | elif color=='red' : print('\033[1;31m%s\033[1;m' % data) 69 | elif color=='yellow' : print('\033[1;33m%s\033[1;m' % data) 70 | elif color=='magenta' : print('\033[1;35m%s\033[1;m' % data) 71 | elif color=='cyan' : print('\033[1;36m%s\033[1;m' % data) 72 | elif color=='white' : print('\033[1;37m%s\033[1;m' % data) 73 | elif color=='crimson' : print('\033[1;38m%s\033[1;m' % data) 74 | else : print(data) 75 | 76 | logo=''' 77 | ___ _ _ ___ _ _ 78 | /___\_ __ | (_)_ __ ___ / __\ |__ ___ ___| | _____ _ __ 79 | // // '_ \| | | '_ \ / _ \ / / | '_ \ / _ \/ __| |/ / _ \ '__| 80 | / \_//| | | | | | | | | __/ / /___| | | | __/ (__| < __/ | 81 | \___/ |_| |_|_|_|_| |_|\___| \____/|_| |_|\___|\___|_|\_\___|_| 82 | 83 | An adaptive URL online checker for python2 and python3 84 | ''' 85 | def main(): 86 | print_color(logo,'green') 87 | if len(sys.argv)!=2: 88 | print_color("Usage: python online-checker.py filename",'blue') 89 | exit() 90 | 91 | f=open(sys.argv[1],'r') 92 | for i in f.readlines(): 93 | workQueue.put(i.strip()) 94 | for i in range(thread_num): 95 | thread = MyThread(workQueue, i) 96 | thread.start() 97 | threads.append(thread) 98 | for t in threads: 99 | t.join() 100 | 101 | if __name__ == '__main__': 102 | main() 103 | --------------------------------------------------------------------------------