app

mail@pastecode.io avatar
unknown
python
3 years ago
24 kB
1
Indexable
Never
import time
import sys
import urllib.request, socket
import requests
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QApplication, QPushButton, QTextEdit, QVBoxLayout, QWidget


def trap_exc_during_debug(*args):
    # when app raises uncaught exception, print info
    print(args)


# install exception hook: without this, uncaught exception would cause application to exit
sys.excepthook = trap_exc_during_debug

        # Laikinam neimam input, o imam iš šito sarašo ip's.
ProxyList = ["185.60.144.87:12323:7_dac1208285:7293b1beb3",
             "185.60.144.88:12323:7_dac1208285:7293b1beb3",
             "185.60.144.89:12323:7_dac1208285:7293b1beb3",
             "185.60.144.90:12323:7_dac1208285:7293b1beb3",
             "185.60.144.91:12323:7_dac1208285:7293b1beb3",
             "proxy.iproyal.com:12323:iproyaladmin:testadminpassword_session-PoAjNBrg",
             "proxy.iproyal.com:12323:iproyaladmin:testadminpassword_session-FUhYEAjm",
             "proxy.iproyal.com:12323:iproyaladmin:testadminpassword_session-2zTrGXLu",
             "proxy.iproyal.com:12323:iproyaladmin:testadminpassword_session-0J2F6pyM"]

ProxyListFinal = []
class Worker(QObject):



    """
    Must derive from QObject in order to emit signals, connect slots to other signals, and operate in a QThread.
    """

    sig_step = pyqtSignal(int,str)  # worker id, step description: emitted every step through work() loop
    sig_done = pyqtSignal(int)  # worker id: emitted at end of work()
    sig_msg = pyqtSignal(str)  # message to be shown to user
    
    
    
    def __init__(self, id: int):
        super().__init__()
        self.__id = id
        self.__abort = False
        self.ProxyList = ProxyList
        self.ProxyListFinal = ProxyListFinal
        
        

    def get_proxy_list(self):
        #ProxyOriginal = self.ProxyList.split('\n')
        ProxyOriginal = self.ProxyList
        for proxy in ProxyOriginal:
            self.splitted = proxy.split(':')
            proxyEdited = (self.splitted[2] + ':' + self.splitted[3] + '@' + self.splitted[0] + ':' + self.splitted[1])
            self.ProxyListFinal.append(proxyEdited)


    #def ipInfo(self, addr=''):
        #from urllib.request import urlopen
        #from json import load
        #if addr == '':
            #url = 'https://ipinfo.io/json'
        #else:
            #url = 'https://ipinfo.io/' + addr + '/json'
        #self.res = urlopen(url)
        # response from url(if res==None then check connection)
        #self.data = load(self.res)
        # will load the json response into data

        # will print the data line by line
        #self.inforaw = ('IP' + ' ' * 17 + '->' + ' ' * 5 + str(self.data['ip']),
                     #'City' + ' ' * 15 + '->' + ' ' * 5 + str(self.data['city']),
                     #'Country' + ' ' * 9 + '->' + ' ' * 5 + str(self.data['country']),
                     #'Organization' + ' ' * 3 + '->' + ' ' * 5 + str(self.data['org']))
        #self.info = '\n'+'\n'.join(self.inforaw)
        #return self.info

    def is_bad_proxy(self, pip):
        try:
            self.address = 'http://www.usa.gov'
            self.proxy_handler = urllib.request.ProxyHandler({'http': pip})
            self.opener = urllib.request.build_opener(self.proxy_handler)
            self.opener.addheaders = [('User-agent', 'Mozilla/5.0')]
            urllib.request.install_opener(self.opener)
            self.sock = urllib.request.urlopen(self.address)
            self.response = requests.get(self.address)
            self.speedraw = (str(round(self.response.elapsed.total_seconds() * 1000)),'ms')
            self.speed = ' '.join(self.speedraw)+' ->'
        except urllib.error.HTTPError as e:
            print('Error code: ', e.code)
            return e.code
        except Exception as detail:
            print("ERROR:", detail)
            return 1
        return 0

    @pyqtSlot()
    def work(self):
        """
        Pretend this worker method does work that takes a long time. During this time, the thread's
        event loop is blocked, except if the application's processEvents() is called: this gives every
        thread (incl. main) a chance to process events, which in this sample means processing signals
        received from GUI (such as abort).
        """
        thread_name = QThread.currentThread().objectName()
        thread_id = int(QThread.currentThreadId())  # cast to int() is necessary
        self.sig_msg.emit('yRunning worker #{} from thread "{}" (#{})'.format(self.__id, thread_name, thread_id))

        x = 1
        self.get_proxy_list()
        i=1
        for step in self.ProxyListFinal:
            if self.is_bad_proxy(step):
                #result = ("Bad Proxy" + ' -> ' + step, self.ipInfo(self.splitted[0]))
                raw = ("Bad Proxy", ' -> ', str(step))
                result = ' '.join(raw)+'_'*67
                self.sig_step.emit(i,result)
                i = i+1
                print(web_address)
                # send good proxy info to log
                app.processEvents() # process emit signal
            else:
                #result = (self.speed, step, "is working", self.ipInfo(self.splitted[0]))
                raw = (str(self.speed), str(step), "is working")
                result = ' '.join(raw)+'\n'+'_'*67
                self.sig_step.emit(i,result)
                i = i+1
                # send bad proxy info to log
                print(web_address)
                app.processEvents() # process emit signal
            if self.__abort:
                # note that "step" value will not necessarily be same for every thread
                self.sig_msg.emit('Worker #{} aborting work at step {}'.format(self.__id, step))
                break
            #self.sig_done.emit(self.__id)

    def abort(self):
        self.sig_msg.emit('Worker #{} notified to abort'.format(self.__id))
        self.__abort = True


class MyWidget(QWidget):
    
    NUM_THREADS = 1

    # sig_start = pyqtSignal()  # needed only due to PyCharm debugger bug (!)
    sig_abort_workers = pyqtSignal()
    
    
    def setupUi(self, MainWindow):
        global web_address
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowModality(QtCore.Qt.NonModal)
        MainWindow.resize(800, 800)
        MainWindow.setMinimumSize(QtCore.QSize(800, 800))
        MainWindow.setMaximumSize(QtCore.QSize(900, 900))
        MainWindow.setAcceptDrops(False)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("static/window-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setWindowOpacity(1.0)
        MainWindow.setStyleSheet("background-color: qradialgradient(spread:pad, cx:0.737, cy:0.318182, radius:0.86, fx:1, fy:0, stop:0 rgba(60, 5, 94, 255), stop:1 rgba(47, 14, 90, 255));")
        MainWindow.setDocumentMode(False)
        MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
        MainWindow.setDockNestingEnabled(False)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setAutoFillBackground(False)
        self.centralwidget.setStyleSheet("")
        self.centralwidget.setObjectName("centralwidget")
        self.logo = QtWidgets.QLabel(self.centralwidget)
        self.logo.setGeometry(QtCore.QRect(30, 30, 251, 71))
        self.logo.setStyleSheet("color: rgb(255, 255, 205,00);\n"
                                "background-color: rgba(0, 0, 0, 0)")
        self.logo.setText("")
        self.logo.setPixmap(QtGui.QPixmap("static/logo-w.png"))
        self.logo.setScaledContents(True)
        self.logo.setObjectName("logo")
        self.web_address_input = QtWidgets.QLineEdit(self.centralwidget)
        web_address = self.web_address_input.text()
        self.web_address_input.setGeometry(QtCore.QRect(30, 340, 260, 33))
        self.web_address_input.setStyleSheet("background-color:#250F49;\n"
                                            "border-radius:10px;\n"
                                            "color:white;\n"
                                            "padding-left:30px;\n"
                                            "font: 9pt \"Exo Medium\";")
        self.web_address_input.setInputMethodHints(QtCore.Qt.ImhNone)
        self.web_address_input.setClearButtonEnabled(False)
        self.web_address_input.setObjectName("web_address_input")
        self.more_text = QtWidgets.QLabel(self.centralwidget)
        self.more_text.setGeometry(QtCore.QRect(50, 140, 311, 110))
        self.more_text.setStyleSheet("color:#8A7BAA;\n"
                                    "font: 25 9pt \"Gotham\";\n"
                                    "background-color: rgba(0, 0, 0, 0)")
        self.more_text.setObjectName("more_text")
        self.web_icon = QtWidgets.QLabel(self.centralwidget)
        self.web_icon.setGeometry(QtCore.QRect(35, 345, 20, 20))
        self.web_icon.setStyleSheet("background-color: rgba(0, 0, 0, 0)")
        self.web_icon.setText("")
        self.web_icon.setPixmap(QtGui.QPixmap("static/web.png"))
        self.web_icon.setScaledContents(True)
        self.web_icon.setObjectName("web_icon")
        self.log = QtWidgets.QTextEdit(self.centralwidget)
        self.log.setGeometry(QtCore.QRect(300, 340, 470, 113))
        self.log.setStyleSheet("background-color:#250F49;\n"
                                        "border-radius: 10px;\n"
                                        "color:white;\n"
                                        "font: 9pt \"Exo Medium\";\n"
                                        "")
        self.log.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.log.setFrameShadow(QtWidgets.QFrame.Plain)
        self.log.setObjectName("log")
        self.enter_proxy_text = QtWidgets.QLabel(self.centralwidget)
        self.enter_proxy_text.setGeometry(QtCore.QRect(300, 320, 291, 16))
        self.enter_proxy_text.setStyleSheet("color:white;\n"
                                            "font: 57 9pt \"Gotham Black\";\n"
                                            "background-color: rgba(0, 0, 0, 0)")
        self.enter_proxy_text.setObjectName("enter_proxy_text")
        self.enter_proxy_detailed_text = QtWidgets.QLabel(self.centralwidget)
        self.enter_proxy_detailed_text.setGeometry(QtCore.QRect(480, 455, 351, 16))
        self.enter_proxy_detailed_text.setStyleSheet("color:#8A7BAA;\n"
                                                    "font: 57 italic 9pt \"Exo Medium\";\n"
                                                    "background-color: rgba(0, 0, 0, 0)")
        self.enter_proxy_detailed_text.setScaledContents(False)
        self.enter_proxy_detailed_text.setObjectName("enter_proxy_detailed_text")
        self.button_stop_threads = QtWidgets.QPushButton(self.centralwidget)
        self.button_stop_threads.setGeometry(QtCore.QRect(30, 420, 80, 33))
        self.button_stop_threads.setStyleSheet("border-radius: 5px 5px 0px 5px;\n"
                                                "color:white;\n"
                                                "font: 57 10pt \"Gotham Black\";\n"
                                                "border-color:#D0349C;\n"
                                                "border-style:solid;\n"
                                                "border-width:2px;")
        self.button_stop_threads.setObjectName("button_stop_threads")
        self.progress = QtWidgets.QTextEdit(self.centralwidget)
        self.progress.setGeometry(QtCore.QRect(30, 480, 740, 250))
        self.progress.setStyleSheet("background-color:#250F49;\n"
                                    "border-radius:6px;\n"
                                    "color:white;\n"
                                    "font: 9pt \"Exo Medium\";")
        self.progress.setReadOnly(True)
        self.progress.setObjectName("progress")
        self.clear_button = QtWidgets.QPushButton(self.centralwidget)
        self.clear_button.setGeometry(QtCore.QRect(210, 420, 80, 33))
        self.clear_button.setStyleSheet("border-radius:6px;\n"
                                        "color:white;\n"
                                        "font: 57 10pt \"Gotham Black\";\n"
                                        "background:#D0349C;")
        self.clear_button.setObjectName("clear_button")
        self.hero = QtWidgets.QLabel(self.centralwidget)
        self.hero.setEnabled(True)
        self.hero.setGeometry(QtCore.QRect(340, 0, 460, 380))
        self.hero.setStyleSheet("color: rgb(255, 255, 205,00);\n"
                                "background-color: rgba(0, 0, 0, 0)")
        self.hero.setText("")
        self.hero.setPixmap(QtGui.QPixmap("static/hero-v2.png"))
        self.hero.setScaledContents(True)
        self.hero.setObjectName("hero")
        self.main_heading = QtWidgets.QLabel(self.centralwidget)
        self.main_heading.setGeometry(QtCore.QRect(50, 110, 231, 60))
        self.main_heading.setStyleSheet("background-color: rgba(0, 0, 0, 0);\n"
                                        "color:white;\n"
                                        "font: 30pt \"Bebas\";")
        self.main_heading.setObjectName("main_heading")
        self.web_button = QtWidgets.QPushButton(self.centralwidget)
        self.web_button.setGeometry(QtCore.QRect(50, 240, 151, 31))
        self.web_button.setStyleSheet("border-radius:10px;\n"
                                        "color:white;\n"
                                        "background-color:#00000000;\n"
                                        "border-style:solid;\n"
                                        "border-width:2px;\n"
                                        "font-family:\"Bebas\";\n"
                                        "font-size:15px;\n"
                                        "border-color: rgb(192, 222, 217);")
        self.web_button.setObjectName("web_button")
        self.web_address_text = QtWidgets.QLabel(self.centralwidget)
        self.web_address_text.setGeometry(QtCore.QRect(30, 320, 291, 20))
        self.web_address_text.setStyleSheet("color:white;\n"
                                            "font: 57 9pt \"Gotham Black\";\n"
                                            "background-color: rgba(0, 0, 0, 0)")
        self.web_address_text.setObjectName("web_address_text")
        self.button_start_threads = QtWidgets.QPushButton(self.centralwidget)
        self.button_start_threads.setGeometry(QtCore.QRect(30, 380, 260, 33))
        self.button_start_threads.setStyleSheet("border-radius:6px;\n"
                                                "color:white;\n"
                                                "font: 57 10pt \"Gotham Black\";\n"
                                                "background:#6B22C3;")
        self.button_start_threads.setObjectName("button_start_threads")
        self.button_start_threads.clicked.connect(self.start_threads)
        self.import_button = QtWidgets.QPushButton(self.centralwidget)
        self.import_button.setGeometry(QtCore.QRect(120, 420, 80, 33))
        self.import_button.setStyleSheet("border-radius:6px;\n"
                                        "color:white;\n"
                                        "font: 57 10pt \"Gotham Black\";\n"
                                        "background:#6B22C3;")
        self.import_button.setObjectName("import_button")
        self.proxy_output_text = QtWidgets.QLabel(self.centralwidget)
        self.proxy_output_text.setGeometry(QtCore.QRect(30, 460, 291, 20))
        self.proxy_output_text.setStyleSheet("color:white;\n"
                                            "font: 57 9pt \"Gotham Black\";\n"
                                            "background-color: rgba(0, 0, 0, 0)")
        self.proxy_output_text.setObjectName("proxy_output_text")
        self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
        self.progressBar.setGeometry(QtCore.QRect(30, 740, 741, 23))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.progressBar.sizePolicy().hasHeightForWidth())
        self.progressBar.setSizePolicy(sizePolicy)
        self.progressBar.setStyleSheet("QProgressBar\n"
                                        "{\n"
                                        "border-radius: 10px;\n"
                                        "border: solid grey;\n"
                                        "background-color:#250F49;\n"
                                        "}\n"
                                        "QProgressBar::chunk \n"
                                        "{background-color: qlineargradient(spread:pad, x1:0, y1:0.5, x2:1, y2:0.5, stop:0 rgba(90, 97, 210, 255), stop:1 rgba(219, 48, 151, 255));\n"
                                        "border-radius :10px;}\n"
                                        "\n"
                                        "")
        self.progressBar.setInputMethodHints(QtCore.Qt.ImhNone)
        self.progressBar.setProperty("value", 75)
        self.progressBar.setTextVisible(False)
        self.progressBar.setInvertedAppearance(False)
        self.progressBar.setObjectName("progressBar")
        self.hero.raise_()
        self.logo.raise_()
        self.web_address_input.raise_()
        self.more_text.raise_()
        self.web_icon.raise_()
        self.log.raise_()
        self.enter_proxy_text.raise_()
        self.enter_proxy_detailed_text.raise_()
        self.button_stop_threads.raise_()
        self.progress.raise_()
        self.clear_button.raise_()
        self.main_heading.raise_()
        self.web_button.raise_()
        self.web_address_text.raise_()
        self.button_start_threads.raise_()
        self.import_button.raise_()
        self.proxy_output_text.raise_()
        self.progressBar.raise_()
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "IPRoyal Proxy Tester"))
        self.web_address_input.setToolTip(_translate("MainWindow", "<html><head/><body><p>asdasd</p></body></html>"))
        self.web_address_input.setText(_translate("MainWindow", "https://www.google.com"))
        self.more_text.setText(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
        "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
        "p, li { white-space: pre-wrap; }\n"
        "</style></head><body style=\" font-family:\'Oswald\'; font-size:9pt; font-weight:400; font-style:normal;line-height:75%\">\n"
        "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">\n"
        "Lorem Ipsum is simply dummy text of the printing and<br>\n"
        "typesetting industry. Lorem Ipsum has been the industry\'s<br>\n"
        "standard dummy text ever since the 1500s, when an unknown<br>\n"
        "printer took a galley of type and scrambled it to make a type specimen book.</p></body></html>"))
        self.enter_proxy_text.setText(_translate("MainWindow", "Enter proxy IP\'s to check:"))
        self.enter_proxy_detailed_text.setText(_translate("MainWindow", "Enter one IP per line. (Format: USER:PASS:IP:PORT)"))
        self.button_stop_threads.setText(_translate("MainWindow", "STOP"))
        self.clear_button.setText(_translate("MainWindow", "CLEAR"))
        self.main_heading.setText(_translate("MainWindow", "IP PROXY TESTER"))
        self.web_button.setText(_translate("MainWindow", "VISIT WWW.IPROYAL.COM"))
        self.web_address_text.setText(_translate("MainWindow", "Web address to check proxy against:"))
        self.button_start_threads.setText(_translate("MainWindow", "TEXT PROXY IP\'S!"))
        self.import_button.setText(_translate("MainWindow", "IMPORT"))
        self.proxy_output_text.setText(_translate("MainWindow", "Checked IP’s:"))

    def start_threads(self):
        #self.log.append('starting {} threads'.format(self.NUM_THREADS))
        self.button_start_threads.setDisabled(True)
        self.button_stop_threads.setEnabled(True)
        #self.log.append(self.log.toPlainText())

        self.__workers_done = 0
        self.__threads = []
        for idx in range(self.NUM_THREADS):
            worker = Worker(idx)
            thread = QThread()
            thread.setObjectName('thread_' + str(idx))
            self.__threads.append((thread, worker))  # need to store worker too otherwise will be gc'd
            worker.moveToThread(thread)

            # get progress messages from worker:
            worker.sig_step.connect(self.on_worker_step)
            worker.sig_done.connect(self.on_worker_done)
            #worker.sig_msg.connect(self.log.append)

            # control worker:
            self.sig_abort_workers.connect(worker.abort)

            # get read to start worker:
            # self.sig_start.connect(worker.work)  # needed due to PyCharm debugger bug (!); comment out next line
            thread.started.connect(worker.work)
            thread.start()  # this will emit 'started' and start thread's event loop

        # self.sig_start.emit()  # needed due to PyCharm debugger bug (!)

    #def get_proxy_list(self):
        #self.proxy_list = self.proxy_input

    @pyqtSlot(int, str)
    def on_worker_step(self, worker_id: int, data: str):
        #self.log.append('Worker #{}: {}'.format(worker_id, data))
        self.progress.append('{}: {}'.format(worker_id, data))


    @pyqtSlot(int)
    def on_worker_done(self, worker_id):
        #self.log.append('worker #{} done'.format(worker_id))
        self.progress.append('-- Worker {} DONE'.format(worker_id))
        self.__workers_done += 1
        if self.__workers_done == self.NUM_THREADS:
            #self.log.append('No more workers active')
            self.button_start_threads.setEnabled(True)
            self.button_stop_threads.setDisabled(True)
            # self.__threads = None

    @pyqtSlot()
    def abort_workers(self):
        self.sig_abort_workers.emit()
        #self.log.append('Asking each worker to abort')
        for thread, worker in self.__threads:  # note nice unpacking by Python, avoids indexing
            thread.quit()  # this will quit **as soon as thread event loop unblocks**
            thread.wait()  # <- so you need to wait for it to *actually* quit

        # even though threads have exited, there may still be messages on the main thread's
        # queue (messages that threads emitted before the abort):
        #self.log.append('All threads exited')
    

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = MyWidget()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())