socks.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:xxNet 作者: drzorm 项目源码 文件源码
def _write_SOCKS5_address(self, addr, file):
        """
        Return the host and port packed for the SOCKS5 protocol,
        and the resolved address as a tuple object.
        """
        host, port = addr
        proxy_type, _, _, rdns, username, password = self.proxy

        if ":" in host:
            addr_bytes = socket.inet_pton(socket.AF_INET6, host)
            file.write(b"\x04" + addr_bytes)
        elif check_ip_valid(host):
            addr_bytes = socket.inet_pton(socket.AF_INET, host)
            file.write(b"\x01" + addr_bytes)
        else:
            if rdns:
                # Resolve remotely
                host_bytes = host.encode('idna')
                file.write(b"\x03" + chr(len(host_bytes)).encode() + host_bytes)
            else:
                # Resolve locally
                addr_bytes = socket.inet_aton(socket.gethostbyname(host))
                file.write(b"\x01" + addr_bytes)
                host = socket.inet_ntoa(addr_bytes)

        file.write(struct.pack(">H", port))
        return host, port
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号