def authSelected(self, method): method = to_binary(method) if method not in self.w.factory.methods: raise e.MethodsNotAcceptedError('no method proprosed was accepted', self.w.factory.methods, method) authMethod = getattr(self.w, 'auth_' + self.w.authMethodMap[method]) authMethod(*self.w.factory.methods[method])
def sendLogin(self, username, password): self.transport.write(b'\x01' + to_binary(chr(len(username))) + username + to_binary(chr(len(password))) + password)
def sendRequest(self, host, port, user): ipaddr = socket.inet_aton(socket.gethostbyname(host)) data = struct.pack(">BBH", c.VER_SOCKS4, c.CMD_CONNECT, port) self.transport.write(data + ipaddr + to_binary(user) + b'\0')
def socks_host(host): return to_binary(chr(c.ATYP_DOMAINNAME)) + to_binary(chr(len(host))) + host