(self, host)
| 257 | self.__proxypeername = (destaddr, destport) |
| 258 | |
| 259 | def __resolvesocks5(self, host): |
| 260 | # Now we can request the actual connection |
| 261 | req = struct.pack('BBB', 0x05, 0xF0, 0x00) |
| 262 | req += chr(0x03).encode() + chr(len(host)).encode() + host |
| 263 | req = req + struct.pack(">H", 8444) |
| 264 | self.sendall(req) |
| 265 | # Get the response |
| 266 | ip = "" |
| 267 | resp = self.__recvall(4) |
| 268 | if resp[0:1] != chr(0x05).encode(): |
| 269 | self.close() |
| 270 | raise GeneralProxyError((1, _generalerrors[1])) |
| 271 | elif resp[1:2] != chr(0x00).encode(): |
| 272 | # Connection failed |
| 273 | self.close() |
| 274 | if ord(resp[1:2])<=8: |
| 275 | raise Socks5Error((ord(resp[1:2]), _socks5errors[ord(resp[1:2])])) |
| 276 | else: |
| 277 | raise Socks5Error((9, _socks5errors[9])) |
| 278 | # Get the bound address/port |
| 279 | elif resp[3:4] == chr(0x01).encode(): |
| 280 | ip = socket.inet_ntoa(self.__recvall(4)) |
| 281 | elif resp[3:4] == chr(0x03).encode(): |
| 282 | resp = resp + self.recv(1) |
| 283 | ip = self.__recvall(ord(resp[4:5])) |
| 284 | else: |
| 285 | self.close() |
| 286 | raise GeneralProxyError((1,_generalerrors[1])) |
| 287 | boundport = struct.unpack(">H", self.__recvall(2))[0] |
| 288 | return ip |
| 289 | |
| 290 | def getproxysockname(self): |
| 291 | """getsockname() -> address info |
no test coverage detected