Skip to content

Commit 2e0a95d

Browse files
committed
Fake the useragent as some tracker lists block the urllib (e.g. newtrackon.com)
1 parent b9334b4 commit 2e0a95d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

transmission-trackers.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@
3838
# Debug output
3939
debug = False
4040

41-
###
41+
### Configuration ends here ###
42+
hdrs = {'User-Agent': 'Mozilla/5.0'}
4243
hosts, ips = set(()), set(())
4344

4445
import transmissionrpc, sys, os, time, socket
4546

4647
if sys.version_info[0] == 2:
47-
from urllib import urlopen
48+
from urllib import Request, urlopen
4849
from urlparse import urlparse
4950
else:
50-
from urllib.request import urlopen
51+
from urllib.request import Request, urlopen
5152
from urllib.parse import urlparse
5253

5354
def lg(msg):
@@ -75,16 +76,19 @@ def validateTrackerURL(url, dns=True):
7576
dbg("Host '{}' is duplicate".format(h))
7677
return False
7778

79+
ipa = set(())
7880
if dns:
7981
try:
80-
ip = socket.gethostbyname(h)
82+
for r in socket.getaddrinfo(h, None):
83+
ipa.add(r[4][0])
8184
except:
8285
lg("Host '{}' is not resolvable".format(h))
8386
return False
8487

85-
if ip in ips:
86-
dbg("Host's '{}' IP '{}' is duplicate".format(h, ip))
87-
return False
88+
for ip in ipa:
89+
if ip in ips:
90+
dbg("Host's '{}' IP '{}' is duplicate".format(h, ip))
91+
return False
8892

8993
ips.add(ip)
9094

@@ -99,7 +103,8 @@ def loadFile(file):
99103
return l
100104

101105
def loadURL(url):
102-
f = urlopen(url)
106+
req = Request(url, headers=hdrs)
107+
f = urlopen(req)
103108
l = parse(f.read().decode("utf-8"))
104109
f.close()
105110
return l

0 commit comments

Comments
 (0)