Skip to content

About

Which destination ports will a proxy tunnel to? Test SSH, SMTP, database and custom ports through an HTTP CONNECT or SOCKS5 proxy, one line per port, Python stdlib only (Proxy302)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

proxy-connect-port-check: which ports will my proxy connect to?

To find out which destination ports a proxy will reach, ask it to open a tunnel to each port on a host that you know is listening, and read its answer port by port. An HTTP proxy answers CONNECT host:port with 200 (tunnel open), 403 (its own rules refuse that port) or 502/504 (it tried and nothing answered). A SOCKS5 proxy answers with a reply code: 0x00 open, 0x02 not allowed by its rules, 0x05 refused by the target, 0x06 timed out. A proxy that works for websites can still refuse SSH on 22, mail on 25 or a database port, because port rules are common: Squid's default configuration, for example, only allows CONNECT to port 443. port_check.py tests a list of ports in parallel and prints one line per port, with the server's first line (an SSH or SMTP banner) when a tunnel opens. Proxy302 maintains this tool and sells proxies: a static residential (ISP) IP costs $7.99 for 30 days, or $0.50 for a one-day test (prices). The script works with any provider's HTTP or SOCKS5 proxy, and the answer it gives is the only reliable statement of what a given proxy allows.

Maintained by Proxy302. MIT licensed.

Usage

git clone https://github.com/proxy302/proxy-connect-port-check
cd proxy-connect-port-check
python3 port_check.py "http://USER:PASS@HOST:PORT" YOUR-SERVER                    # default port list
python3 port_check.py "socks5h://USER:PASS@HOST:PORT" YOUR-SERVER --ports 22,2222
python3 port_check.py "http://USER:PASS@HOST:PORT" portquiz.net --ports 25,465,587

USER, PASS, HOST and PORT are placeholders; percent-encode @ : / # % in the password. Python 3.8 or later, standard library only.

Which target? Use a server you control where the ports you care about are really listening, or a public test host that listens on every TCP port, such as portquiz.net. Testing against a host where nothing listens only tells you "target refused", which says nothing about the proxy's rules.

Default ports: 22, 25, 80, 443, 465, 587, 993, 3306, 5432, 8080, 8443. Options: --ports (comma-separated), --timeout S per port (default 10), --parallel N (default 4), --banner-wait S (default 2).

The exit code is 0 when every port got a clear answer, 1 when any port got no answer or a broken one, and 3 when the proxy rejected the login.

Example output

Recorded on 23 November 2026 on a Mac, against a test proxy running locally (HTTP on 23128, SOCKS5 on 21080, user alice) that only allows tunnels to ports 28022, 28080 and 28443. Behind it: a fake SSH server on 28022, a fake mail server on 28025, a plain web server on 28081 and a TLS server on 28443; nothing listens on 28080. High port numbers stand in for 22, 25, 80 and 443 because those need administrator rights to open. Real output, nothing edited.

Through the HTTP proxy:

$ python3 port_check.py "http://alice:s3cret@127.0.0.1:23128" 127.0.0.1 --ports 28022,28025,28080,28081,28443
proxy   http://alice:****@127.0.0.1:23128
target  127.0.0.1   ports: 28022, 28025, 28080, 28081, 28443

PORT   SERVICE            RESULT            TIME     DETAIL
28022                     open              1 ms     HTTP/1.1 200 Connection established
                                                     server says: SSH-2.0-TestBed
28025                     blocked by proxy  1 ms     HTTP/1.1 403 Forbidden
28080                     target refused    1 ms     HTTP/1.1 502 Bad Gateway (or the name did not resolve at the proxy)
28081                     blocked by proxy  1 ms     HTTP/1.1 403 Forbidden
28443                     open              1 ms     HTTP/1.1 200 Connection established
                                                     server says: (no banner: the service waits for the client to speak first)

open:             28022, 28443
blocked by proxy: 28025, 28081
target refused:   28080

open             = the proxy opened a tunnel and something answered at the target
blocked by proxy = the proxy's own rules refuse that port; no client setting changes this
target refused / target timeout = the proxy allowed it, but nothing listens there or it is filtered
(exit code 0)

Through the SOCKS5 proxy, with the name resolved by the proxy (socks5h):

$ python3 port_check.py "socks5h://alice:s3cret@127.0.0.1:21080" localhost --ports 28022,28025,28080,28443
proxy   socks5h://alice:****@127.0.0.1:21080
target  localhost   ports: 28022, 28025, 28080, 28443

PORT   SERVICE            RESULT            TIME     DETAIL
28022                     open              6 ms     SOCKS5 reply 0x00: succeeded
                                                     server says: SSH-2.0-TestBed
28025                     blocked by proxy  5 ms     SOCKS5 reply 0x02: not allowed by the proxy's rules
28080                     target refused    6 ms     SOCKS5 reply 0x05: the target refused the connection
28443                     open              6 ms     SOCKS5 reply 0x00: succeeded
                                                     server says: (no banner: the service waits for the client to speak first)

open:             28022, 28443
blocked by proxy: 28025
target refused:   28080

open             = the proxy opened a tunnel and something answered at the target
blocked by proxy = the proxy's own rules refuse that port; no client setting changes this
target refused / target timeout = the proxy allowed it, but nothing listens there or it is filtered
(exit code 0)

With real ports the SERVICE column is filled in (22 SSH, 25 SMTP, 3306 MySQL and so on).

Reading the result

Result What happened What you can do
open The proxy connected you, and the target accepted Use it. A banner confirms which service answered
blocked by proxy HTTP 403 or SOCKS5 0x02: the proxy will not connect to that port Nothing on your side changes this. Use another port the service offers (587 or 465 instead of 25, SSH on 443 if your server offers it), or a different kind of exit
target refused HTTP 502 or SOCKS5 0x05: the proxy tried, the target said no Check the port on your server and its firewall
target timeout HTTP 504 or SOCKS5 0x06: the proxy tried, no answer A firewall in front of the target drops the packets, or the host is down
no answer The proxy itself did not reply in time Run proxy-error-diagnose on it

Some notes from building it:

  • Port 25 is special. Outbound port 25 is widely filtered on home broadband, cloud servers and proxy services, because it is how spam is delivered. Mail clients and scripts should send on 587 or 465 with a login, which is what mail providers expect anyway.
  • Banner-first and client-first services. SSH, SMTP, FTP and MySQL speak first, so you see a banner. HTTP, HTTPS and PostgreSQL wait for the client, so "no banner" there is normal.
  • HTTP proxies and plain HTTP. For http:// web pages, browsers do not use CONNECT at all; they send GET http://... to the proxy. A proxy can therefore serve port 80 pages while refusing CONNECT to port 80. This script tests CONNECT, which is what SSH, mail, database clients and every https:// request use.

Related

Checked 23 November 2026.

About

Which destination ports will a proxy tunnel to? Test SSH, SMTP, database and custom ports through an HTTP CONNECT or SOCKS5 proxy, one line per port, Python stdlib only (Proxy302)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages