Tunneling TCP traffic through HTTP proxy

It is not obvious but possible to use HTTP proxy to tunnel arbitrary TCP traffic for applications and protocols other than HTTP. Most http proxies support CONNECT command that is used to establish secure https connections. This command literary creates a tunnel for the requested address. And all the data between destination and client is redirected through the proxy without any modification. This is because https traffic is encrypted and proxy don't have any access to the underlying information being transmitted.

So if your application establish only one-way connection to the destination you can use HTTP proxy that supports CONNECT to make connections.

Our proxies also support CONNECT and can be used to tunnel TCP connections. Moreover all the IP rotation is also supported and you can request a new IP on every new session or specify outgoing locations using headers or username API (see docs)

Here is an example in python how to tunnel connection through our proxies:

def parse_proxy_string(proxy):
    auth, addr = proxy.split('@')
    user, pwd = auth.split(':')
    host, port = addr.split(':')
    token = base64.b64encode(auth.encode()).strip()
    return {
        'user': user,
        'password': pwd,
        'host': host,
        'port': int(port),
        'token': token.decode(),

def connect_proxy(sock, proxy, target_host, target_port):
        sock.connect((proxy['host'], proxy['port']))
        msg = (
            'CONNECT {host}:{port} HTTP/1.1\r\n'
            'X-BOTPROXY-SESSION: {session}\r\n'
            'Proxy-Authorization: Basic {auth}\r\n\r\n').format(
                session=str(random.randint(0, 65536)),
        res = sock.recv(100)
        res = res.decode('ascii', errors='ignore')
        res = [x for x in [x.strip() for x in res.split('\n')] if x]
        if not '200' in res[0]:
            raise Exception(res)
        for hdr in res[1:]:
            print('Proxy response: %s', hdr)
    except Exception as exc:
            'Proxy connect error (%s) to %s:%d',
            exc, proxy['host'], proxy['port'])
        return False
    return True

def main():
    proxy = parse_proxy_string("proxy_user:[email protected]:8080")
    target_host = "your.host.com"
    target_port = 55432 # destination port
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        self.connect_proxy(sock, proxy, target_host, target_port):

        # rest of the code

In this example each new connection will initiate a new BotProxy session ensuring a new IP from the available pool of addresses. Please note that we block the following destination ports 21, 22, 23, 25, 465, 587, 993, 2525, 2526 (telnet, ftp and smtp) to avoid malicious behavior which is also against our Acceptable Use Policy. However don't forget that you can contact support anytime if you have questions or need to use these ports in your application.

BotProxy: Rotating Proxies Made For Professionals

Connect your software to ultra fast rotating proxies with daily fresh IPs and worldwide locations in minutes. We allow full speed multithreaded connections and charge only for bandwidth used. Typical integrations take less than 5 minutes into any script or application.

Sign Up or learn more