Python socks 模块,py() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用socks.py()

项目:Malicious_Domain_Whois    作者:h-j-13    | 项目源码 | 文件源码
def _connect(self):
        """??????whois??
        ???socks.py (ver 1.5.7)"""
        # whois???ip???ip
        global _proxy_socks
        self.tcpCliSock = socks.socksocket()  # ??socket??
        self.tcpCliSock.settimeout(TIMEOUT)  # ??????
        data_result = ""
        try:
            self.tcpCliSock.connect((self.whois_srv, 43))  # ??whois???
            self.tcpCliSock.send(self.request_data + '\r\n')  # ????
        except Exception as e:  # Exception??socks.py ??????
            if str(e).find("timed out") != -1 or \
                            str(e).find("TTL expired") != -1:  # ????
                self.tcpCliSock.close()
                return "ERROR -1"
            elif str(e).find("Temporary failure in name resolution") != -1 or \
                            str(e).find("cannot connect to identd on the client") != -1 or \
                            str(e).find("unreachable") != -1:
                self.tcpCliSock.close()
                return "ERROR -2"
            else:
                self.tcpCliSock.close()
                return "ERROR OTHER"
        # ????
        while True:
            try:
                data_rcv = self.tcpCliSock.recv(1024)  # ??????
            except:
                self.tcpCliSock.close()
                return "ERROR -3"
            if not len(data_rcv):
                self.tcpCliSock.close()
                return data_result  # ??????
            data_result = data_result + data_rcv  # ????????
项目:com_top_whois_service    作者:h-j-13    | 项目源码 | 文件源码
def _connect(self):
        """??????whois??
        ???socks.py (ver 1.5.7)"""
        # whois???ip???ip
        global _server_ip, _proxy_socks
        host = _server_ip.get_server_ip(self.whois_srv)  # ?????
        host = host if host else self.whois_srv  # ??ip????????????
        self.tcpCliSock = socks.socksocket()  # ??socket??
        self.tcpCliSock.settimeout(TIMEOUT)  # ??????
        if Proxy_Flag:  # socks????
            proxy_info = _proxy_socks.get_proxy_socks(self.whois_srv)  # ??IP
            if proxy_info is not None:
                # ????
                if proxy_info['mode'] == 'SOCKS5':
                    self.tcpCliSock.set_proxy(proxy_type=socks.SOCKS5,  # socks??
                                              addr=proxy_info['ip'],  # socks???
                                              port=proxy_info['port'],  # ??
                                              username=proxy_info['username'],  # ???
                                              password=proxy_info['password'])  # ??

                elif proxy_info['mode'] == 'SOCKS4':
                    self.tcpCliSock.set_proxy(proxy_type=socks.SOCKS4,  # socks??
                                              addr=proxy_info['ip'],  # socks???
                                              port=proxy_info['port'])  # ??
        data_result = ""
        try:
            self.tcpCliSock.connect((host, 43))  # ??whois???
            self.tcpCliSock.send(self.request_data + '\r\n')  # ????
        except Exception as e:  # Exception??socks.py ??????
            if str(e).find("timed out") != -1 or \
                            str(e).find("TTL expired") != -1:  # ????
                self.tcpCliSock.close()
                return "ERROR -1"
            elif str(e).find("Temporary failure in name resolution") != -1 or \
                            str(e).find("cannot connect to identd on the client") != -1 or \
                            str(e).find("unreachable") != -1:
                self.tcpCliSock.close()
                return "ERROR -2"
            else:
                self.tcpCliSock.close()
                return "ERROR OTHER"
        # ????
        while True:
            try:
                data_rcv = self.tcpCliSock.recv(1024)  # ??????
            except:
                self.tcpCliSock.close()
                return "ERROR -3"
            if not len(data_rcv):
                self.tcpCliSock.close()
                return data_result  # ??????
            data_result = data_result + data_rcv  # ????????
项目:Malicious_Domain_Whois    作者:h-j-13    | 项目源码 | 文件源码
def _connect(self):
        """??????whois??
        ???socks.py (ver 1.5.7)"""
        # whois???ip???ip
        global _server_ip, _proxy_socks
        host = _server_ip.get_server_ip(self.whois_srv)  # ?????
        host = host if host else self.whois_srv  # ??ip????????????
        self.tcpCliSock = socks.socksocket()  # ??socket??
        self.tcpCliSock.settimeout(TIMEOUT)  # ??????
        if Proxy_Flag:  # socks????
            proxy_info = _proxy_socks.get_proxy_socks(self.whois_srv)  # ??IP
            if proxy_info is not None:
                # ????
                if proxy_info['mode'] == 'SOCKS5':
                    self.tcpCliSock.set_proxy(proxy_type=socks.SOCKS5,  # socks??
                                              addr=proxy_info['ip'],  # socks???
                                              port=proxy_info['port'],  # ??
                                              username=proxy_info['username'],  # ???
                                              password=proxy_info['password'])  # ??

                elif proxy_info['mode'] == 'SOCKS4':
                    self.tcpCliSock.set_proxy(proxy_type=socks.SOCKS4,  # socks??
                                              addr=proxy_info['ip'],  # socks???
                                              port=proxy_info['port'])  # ??
        data_result = ""
        try:
            self.tcpCliSock.connect((host, 43))  # ??whois???
            self.tcpCliSock.send(self.request_data + '\r\n')  # ????
        except Exception as e:  # Exception??socks.py ??????
            if str(e).find("timed out") != -1 or \
                            str(e).find("TTL expired") != -1:  # ????
                self.tcpCliSock.close()
                return "ERROR -1"
            elif str(e).find("Temporary failure in name resolution") != -1 or \
                            str(e).find("cannot connect to identd on the client") != -1 or \
                            str(e).find("unreachable") != -1:
                self.tcpCliSock.close()
                return "ERROR -2"
            else:
                self.tcpCliSock.close()
                return "ERROR OTHER"
        # ????
        while True:
            try:
                data_rcv = self.tcpCliSock.recv(1024)  # ??????
            except:
                self.tcpCliSock.close()
                return "ERROR -3"
            if not len(data_rcv):
                self.tcpCliSock.close()
                return data_result  # ??????
            data_result = data_result + data_rcv  # ????????