diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-10-18 21:28:39 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-10-18 21:28:39 +0200 |
commit | f34aec9d70f48200c0e46db476dff9ee06357707 (patch) | |
tree | 1b272c8dd71df1a6297a4882324f266b23ed65ff /module/ThreadManager.py | |
parent | closed #158 (diff) | |
download | pyload-f34aec9d70f48200c0e46db476dff9ee06357707.tar.xz |
new ip retrieve
Diffstat (limited to 'module/ThreadManager.py')
-rw-r--r-- | module/ThreadManager.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/module/ThreadManager.py b/module/ThreadManager.py index f46f816e4..eba23f28c 100644 --- a/module/ThreadManager.py +++ b/module/ThreadManager.py @@ -24,6 +24,7 @@ from subprocess import Popen from threading import Event from time import sleep from traceback import print_exc +from random import choice import pycurl import PluginThread @@ -126,7 +127,7 @@ class ThreadManager: while [x.active.plugin.waiting for x in self.threads if x.active].count(True) != 0: sleep(0.25) - ip = re.match(".*Current IP Address: (.*)</body>.*", getURL("http://checkip.dyndns.org/")).group(1) + ip = self.getIP() self.core.hookManager.beforeReconnecting(ip) @@ -144,19 +145,30 @@ class ThreadManager: reconn.wait() sleep(1) - ip = "" - while ip == "": - try: - ip = re.match(".*Current IP Address: (.*)</body>.*", getURL("http://checkip.dyndns.org/")).group(1) #get new ip - except: - ip = "" - sleep(1) + ip = self.getIP() self.core.hookManager.afterReconnecting(ip) self.log.info(_("Reconnected, new IP: %s") % ip) self.reconnecting.clear() + def getIP(self): + """retrieve current ip""" + services = [("http://www.whatismyip.com/automation/n09230945.asp", "(\S+)"), + ("http://checkip.dyndns.org/",".*Current IP Address: (\S+)</body>.*")] + + ip = "" + while not ip: + try: + sv = choice(services) + ip = getURL(sv[0]) + ip = re.match(sv[1], ip).group(1) + except: + ip = "" + sleep(1) + + return ip + #---------------------------------------------------------------------- def checkThreadCount(self): """checks if there are need for increasing or reducing thread count""" |