Created
April 12, 2022 07:51
-
-
Save alastairhm/81ce159a0825068793a920fe4a88e235 to your computer and use it in GitHub Desktop.
Check if port is open TCP/UDP in Python, zero result means connect is made.
This file contains 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
def check_tcp(host,ip): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
result = sock.connect_ex((host,ip)) | |
print(result) | |
sock.close() | |
def check_udp(host,ip): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
result = sock.connect_ex((host,ip)) | |
print(result) | |
sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment