Last active
October 24, 2023 02:47
-
-
Save pixelvm/d840d35e0ba1d52269af8fa3bf703442 to your computer and use it in GitHub Desktop.
测试 tcp 是否能够连通
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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