Skip to content

Instantly share code, notes, and snippets.

@pixelvm
Last active October 24, 2023 02:47
Show Gist options
  • Select an option

  • Save pixelvm/d840d35e0ba1d52269af8fa3bf703442 to your computer and use it in GitHub Desktop.

Select an option

Save pixelvm/d840d35e0ba1d52269af8fa3bf703442 to your computer and use it in GitHub Desktop.
测试 tcp 是否能够连通
# -*- coding: UTF-8 -*-
import socket
def test_tcp_conn(ipaddr, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((ipaddr, port))
if result == 0:
print("{}:{} Open".format(ipaddr, port))
sock.close()
test_tcp_conn('115.215.255.169', 1723);
test_tcp_conn('49.235.81.230', 8423);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment