-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.py
More file actions
executable file
·182 lines (161 loc) · 5.37 KB
/
site.py
File metadata and controls
executable file
·182 lines (161 loc) · 5.37 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/python
"""
to install:
# pip install beautifulsoup4 OR apt-get install python-bs4
# apt-get install python-html5lib
# apt-get install python-mysqldb
"""
import urllib2
import sys
import re
import time
import MySQLdb as mdb
from time import sleep
from bs4 import BeautifulSoup
import os
from sst.actions import *
import easygui as eg
def mysqlInsert(domain_name, load_time, t):
print load_time;
con = None
if load_time > 300:
load_time2 = str(load_time)
os.system("echo "+ domain_name +" >> /root/lyubo/down_domains")
os.system("echo %s %s %s >> /root/lyubo/down_domains4" % (url, load_time2, t))
try:
con = mdb.connect('192.168.50.211', 'sitedxr_stats', 'Stats123', 'sitedxr_dom')
cur = con.cursor()
data = "INSERT INTO domains_stats ( domain , load_time , check_time ) VALUES ( '"+ str(domain_name) + "', '%f' , NOW() )" % (load_time)
cur.execute(data)
con.commit()
except mdb.Error, e:
print "mysqlInsert: ",e
sys.exit(1)
finally:
if con:
con.close()
#url='http://' + str(sys.argv[1])
def gui():
t = "Check Web Page Speed v 1.0"
url2 = eg.enterbox(msg='Enter web site URL.', title='Web Page Speed v 1.0', default =' ', strip = True, image=None, root=None)
# eg.exceptionbox(msg="You entered %s" % url2,title="Web Page Speed v 1.0" )
# return url2
msg = "Do you want to continue check %s ?" % url2
title = "Please Confirm to continue"
if eg.ccbox(msg, title):
pass
return url2
else:
sys.exit(0)
url2 = gui()
url = 'http://' + str(url2)
def suspended(url):
urldata = urllib2.urlopen(url, timeout = 25 ).read()
try:
# urldata = urllib2.urlopen(url, timeout = 25 ).read()
s = BeautifulSoup(urldata, "html5lib")
t = s.title.string
print t
if t == "Account Suspended":
print "%s --- Suspended" % (url)
# return
exit(1)
elif t == "503 Service Temporarily Unavailable":
print "Domain ---%s--- 503 | %s" % (url, t)
elif t == "Default Web Site Page":
print "Domain ---%s--- Default Web Page | %s" % (url, t)
except:
#print t
#return
exit(1)
return
#suspended(url)
def s_loader( url, check ):
# suspended(url)
start_time = time.time()
urldata = urllib2.urlopen(url, timeout = 25 ).read()
load_time = time.time() - start_time
#print "url: "+ url + " load %f " %(load_time)
if check == 1 and load_time > 5:
time.sleep(5)
#print url + " step 1 > 4: load_time : %f" % (load_time)
load_time2 = s_loader(url, '0')
else :
load_time2 = load_time
if check == 1 and load_time2 > 5:
time.sleep(5)
#print url + " step 2 > 4: load_time2 : %f" % (load_time2)
load_time3 = s_loader(url, '0')
else :
load_time3 = load_time2
soup = BeautifulSoup(urldata, "html5lib")
# print soup
#print soup.find_all('img')
#print soup.title.string
t = soup.title.string
broi = str(len(soup.find_all('img')))
if soup.find_all('img') == "[]" and broi==0 or soup.title.string == "Account Suspended":
# if soup.title() != "503 Service Temporarily Unavailable":
print soup.title.string
# suspended(urldata)
load_time = 999.9
return load_time
else:
return ( ( load_time + load_time2 + load_time3 ) / 3 )
print soup.title()
print "OK it's Working"
# suspended()
#url='http://' + str(sys.argv[1])
check = 1
def title(url):
try:
urldata = urllib2.urlopen(url, timeout = 25 ).read()
soup = BeautifulSoup(urldata, "html5lib")
# print "OK it's Working"
print soup.title.string
return soup.title.string
except:
print "Not resolving"
return
#title()
try:
load_time = s_loader(url, check)
t = title(url)
#eg.msgbox("Web page Speed test %s\n Site Title: %s" %(load_time, t))
#eg.exceptionbox(msg="You entered %s" % t,title="Web Page Speed v 1.0" )
eg.textbox(msg='', title=' ', text='Wep site title : %s\n Web site load speed : %s' %(t, load_time), codebox=0)
except:
title1 = title(url)
# check again after 5 sec if it reaaly down
print "can not check sleep for 8 sec 'n try again"
sleep(8)
try:
print "try for second time Domain Error : %s" % (title1)
load_time = s_loader(url, check)
#suspended(url)
except:
sleep(10)
try:
print "try for the next time"
load_time = s_loader(url, check)
title()
except:
sleep(6)
try:
print "try for the last time"
load_time = s_loader(url, check)
title(url)
except:
print " =============== Error loading domain : " + str(url2)
title(url)
notopen = 999.9
t = title(url)
#eg.textbox(msg='', title=' ', text='Wep site title : %s\n Web site load speed : %s' %(t, notopen), codebox=0)
mysqlInsert(url2, notopen, t)
# exit(1)
# OK add to mysql
#t = title(url)
#print t
t2 = mysqlInsert(url2, load_time, t)
#eg.msgbox("Web page Speed test %s" %t2)
#eg.exceptionbox(msg="You entered %s" % t2,title="Web Page Speed v 1.0" )