The goal was to use this as a ProxyCommand for ssh but it does not work: $ ssh -o ProxyCommand="python nc.py socks4 ${PROXY_HOST} ${PROXY_PORT} %h %p" user@host 'command' Connection to UNKNOWN port ...