Skip to content

Instantly share code, notes, and snippets.

@jxinging
Last active August 29, 2018 06:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jxinging/47048f2928c80ca7140c to your computer and use it in GitHub Desktop.
Save jxinging/47048f2928c80ca7140c to your computer and use it in GitHub Desktop.
# 生成 socks5 协议的连接命令16进制数据,用于 haproxy的 tcp-check send-binary
# 参考:
# - <https://zh.wikipedia.org/wiki/SOCKS#SOCKS5>, "SOCKS5请求格式" 部分
# - <http://cbonte.github.io/haproxy-dconv/configuration-1.7.html#4.2-tcp-check%20send-binary>
socks5_connect_binary = lambda domain, port: "05010003"+"%02x" % len(domain)+"".join(["%02x" % ord(x) for x in domain])+"%04x" % int(port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment