Proxie's testen mit Multi threading

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
Sannes
User
Beiträge: 7
Registriert: Mittwoch 22. April 2009, 21:27

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?

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
    
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Hallo Sannes, willkommen im Forum,

Du könntest versuchen ``start`` tatsächlich auch aufzurufen statt nur hinzuschreiben.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Sannes
User
Beiträge: 7
Registriert: Mittwoch 22. April 2009, 21:27

Ups :oops:

Super tip und ich bin super doof ;) Danke
Antworten