Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check If Port is Open in Python3?

In python 3 Given an IP address, I want to check if a specefic port is open for TCP Connection. How can I do that?

Please Note, I don’t want to wait at all. If no response was recieved immediately then just report it’s closed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is a Python3 example I got from https://www.kite.com/python/answers/how-to-check-if-a-network-port-is-open-in-python

import socket

a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

port = 8080
location = ("127.0.0.1", port)
check = a_socket.connect_ex(location)

if result == 0:
   print("Port is open")
else:
   print("Port is not open")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading