check remote port is open or not using python
def port_check(HOST): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((HOST, int(22))) s.shutdown(2) return True except: return False
Here is what the above code is Doing:
1. It’s creating a socket object.
2. It’s trying to connect to the host on port 22.
3. If it can connect, it shuts down the socket.
4. If it can’t connect, it returns false.