forked from TideSec/WDScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
39 lines (29 loc) · 766 Bytes
/
Copy pathcommon.py
File metadata and controls
39 lines (29 loc) · 766 Bytes
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
#!/usr/bin/env python
#
# Common functions
#
import time
import urlparse
def get_time():
return time.strftime('%H:%M:%S', time.localtime())
def parse_url(url):
_ = urlparse.urlparse(url, 'http')
if not _.netloc:
_ = urlparse.urlparse('http://' + url, 'http')
return _.scheme, _.netloc, _.path if _.path else '/'
def decode_response_text(txt, charset=None):
if charset:
try:
return txt.decode(charset)
except:
pass
for _ in ['UTF-8', 'GB2312', 'GBK', 'iso-8859-1', 'big5']:
try:
return txt.decode(_)
except:
pass
try:
return txt.decode('ascii', 'ignore')
except:
pass
raise Exception('Fail to decode response Text')