forked from brock7/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlutil.py
executable file
·83 lines (81 loc) · 1 KB
/
urlutil.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
topHostPostfix = (
'.com','.la','.io',
'.co',
'.info',
'.net',
'.org',
'.me',
'.mobi',
'.us',
'.biz',
'.xxx',
'.ca',
'.co.jp',
'.com.cn',
'.net.cn',
'.org.cn',
'.mx',
'.tv',
'.ws',
'.ag',
'.com.ag',
'.net.ag',
'.org.ag',
'.am',
'.asia',
'.at',
'.be',
'.com.br',
'.net.br',
'.bz',
'.com.bz',
'.net.bz',
'.cc',
'.com.co',
'.net.co',
'.nom.co',
'.de',
'.es',
'.com.es',
'.nom.es',
'.org.es',
'.eu',
'.fm',
'.fr',
'.gs',
'.in',
'.co.in',
'.firm.in',
'.gen.in',
'.ind.in',
'.net.in',
'.org.in',
'.it',
'.jobs',
'.jp',
'.ms',
'.com.mx',
'.nl',
'.nu',
'.co.nz',
'.net.nz',
'.org.nz',
'.se',
'.tc',
'.tk',
'.tw',
'.com.tw',
'.idv.tw',
'.org.tw',
'.hk',
'.co.uk',
'.me.uk',
'.org.uk',
'.vg')
def get_top_host(url):
parts = urlparse(url)
host = parts.netloc
extractPattern = r'[^\.]+('+'|'.join([h.replace('.',r'\.') for h in topHostPostfix])+')$'
pattern = re.compile(extractPattern,re.IGNORECASE)
m = pattern.search(host)
return m.group() if m else host