Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] check if port is open or closed #20

Open
RaSan147 opened this issue Jun 24, 2022 · 0 comments
Open

[FEAT] check if port is open or closed #20

RaSan147 opened this issue Jun 24, 2022 · 0 comments
Labels
enhancement ✨ New feature or request

Comments

@RaSan147
Copy link
Owner

here's how:

import socket

HOST = "localhost"
PORT = 443

# Creates a new socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Try to connect to the given host and port
if sock.connect_ex((HOST, PORT)) == 0:
    print("Port " + str(PORT) + " is open") # Connected successfully
else:
    print("Port " + str(PORT) + " is closed") # Failed to connect because port is in use (or bad host)

# Close the connection
sock.close()
@RaSan147 RaSan147 added the enhancement ✨ New feature or request label Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant