-
Notifications
You must be signed in to change notification settings - Fork 6
/
get_sites_http_status.py
executable file
·65 lines (52 loc) · 1.85 KB
/
get_sites_http_status.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python2
"""
Script :get_sites_http_status.py
Author :Julio Sanz
Website :www.elarraydejota.com
Email :[email protected]
Description :Python script to check HTTP status of a list of sites defined in file
(passed as an argument to the script)
The file should be written with a website per line, example:
www.google.com
www.yahoo.com
www.opendns.com
...
Dependencies :This scrip has been written using Python 2.7.9
Usage :python get_sites_http_status.py [sitelist]
License :GPLv3
"""
# =======================
# MODULES IMPORTS
# =======================
import httplib,sys
# =======================
# VARIABLES
# =======================
# Location of sitelist file
sites = sys.argv[1]
# =======================
# FUNCTIONS
# =======================
def get_sites_status(sites_a):
# Create list reading the file
with open(sites_a, 'r') as f:
sitelist = f.read().splitlines()
# Loop through the list and check site by site. At the end, format the output with some decency
print "{0:25} {1:15} {2:15}".format("Site", "Status", "Reason")
print "-"*50
for site in sitelist:
conn = httplib.HTTPConnection(site)
conn.request("HEAD", "/")
response = conn.getresponse()
#print "Site {0:25} Response Status {1:5} Reason {2:15}".format(p, str(response.status), str(response.reason))
print "{0:25} {1:15} {2:15}".format(site, str(response.status), str(response.reason))
return 0
def how_to_use():
print "This script needs at least one parameter"
print "Launch this way -> python get_sites_status.py [location_of_sitelist_file]"
return 1
# =======================
# MAIN
# =======================
if __name__ == '__main__':
get_sites_status(sites)