Proxie's testen mit Multi threading
Verfasst: Mittwoch 22. April 2009, 21:31
Hallo alle miteinander,
Bin ein ziemlicher Anfänger, mal gleich vorneweg
. IIch hab mir ein Tutorial über Multi Threading durchgelesen und einige kurze snippets rauskopiert. Ich habe vor kurzer Zeit einen Proxy tester geschrieben der nach und nach die Proxie's mit urllib2 einfach auf Google verbindet. Diesen wollte ich jetzt umrüsten mit mehreren Thread's. Bekomme bei dem Script keinerlei Fehlermeldung etc. das script ist innerhalb von ner Sekunde gelaufen und es passiert nichts. Was mach ich bloss falsch?
Bin ein ziemlicher Anfänger, mal gleich vorneweg

Code: Alles auswählen
import urllib2, threading
url = urllib2
class SocketThread(threading.Thread):
def __init__ (self, proxy):
self.proxy = proxy
threading.Thread.__init__ (self)
def run(self):
self.proxy = self.proxy.rstrip()
self.proxy = self.proxy.replace(" ", "")
proxysupport = urllib2.ProxyHandler({"http" : self.proxy})
opener = urllib2.build_opener(proxysupport)
urllib2.install_opener(opener)
Request = urllib2.Request("http://www.google.de")
try:
try:
open = urllib2.urlopen(Request)
print "== " + self.proxy + "\t\t== Works!"
open.close()
except (socket.error,httplib.CannotSendRequest,httplib.ResponseNotReady,httplib.BadStatusLine):
print "== " + self.proxy + "\t\t== Can't request"
except url.URLError, e:
ErrorString = str(e)
if "timed out" in ErrorString:
print "== " + self.proxy + "\t\t== Timed out!"
elif "111" in ErrorString:
print "== " + self.proxy + "\t\t== Connection refused!"
elif "113" in ErrorString:
print "== " + self.proxy + "\t\t== No route to host!"
elif "503" in ErrorString:
print "== " + self.proxy + "\t\t== Service unavailable!"
elif "404" in ErrorString:
print "== " + self.proxy + "\t\t== Not found!"
elif "400" in ErrorString:
print "== " + self.proxy + "\t\t== Bad request!"
elif "50" in ErrorString:
print "== " + self.proxy + "\t\t== Proxy error!"
elif "403" in ErrorString:
print "== " + self.proxy + "\t\t== Forbidden!"
elif "401" in ErrorString:
print "== " + self.proxy + "\t\t== Authorization required!"
else:
print "== " + self.proxy + "\t\t== Unknown!"
proxylist = open("1.txt", "r")
for line in proxylist:
SocketThread(line).start