-
Notifications
You must be signed in to change notification settings - Fork 25
/
upcheck.py
45 lines (32 loc) · 1.05 KB
/
upcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# Kudos to Reuven from LinuxJournal for the backbone: https://www.linuxjournal.com/content/threading-python
import sys
import requests
import threading
from queue import Queue
urls = ["https://%s"%line.strip('\n') for line in open(sys.argv[1],'r')]
queue = Queue()
threads = []
def get_length(url):
try:
response = requests.get(url)
queue.put((url, str(response.status_code)))
except requests.packages.urllib3.exceptions.LocationValueError as ee:
queue.put("Location value error for "+url)
except requests.exceptions.SSLError as eee:
queue.put("SSL error, please verify this manually "+url)
except requests.exceptions.ConnectionError as e:
queue.put("Could not connect to "+url)
except Exception as eeee:
print(eeee.message)
print("There are %s"%len(urls)+" urls to be checked...")
for url in urls:
t = threading.Thread(target=get_length, args=(url,))
threads.append(t)
t.start()
for one_thread in threads:
one_thread.join()
while not queue.empty():
url = queue.get()
if "Could not connect" not in url:
print(url)