5 ways to Check a remote port is open in Linux

Updated: Feb 2

Checking remote port status is a common task for Linux admin. Now we collect 5 different ways for this task. We don't need to install any package if we use the following two python commands. We need install package if we choose nc, nmap,telnet.


Use nc command to check the remote port is open

$ nc [-options] [HostName or IP] [PortNumber]

$ nc -zvw10 192.168.0.1 22

  • z: zero-I/O mode which is used for scanning

  • v: for verbose output

  • w10: timeout wait seconds

Use nmap to check the remote port is open

$ nmap [-options] [HostName or IP] [-p] [PortNumber]

nmap 192.168.0.1 -p 22

Use telnet to check the remote port is open

$ telnet [HostName or IP] [PortNumber]

telnet 192.168.0.1 22

Use python telnet to check remote port is open

python -c "import telnetlib; tel=telnetlib.Telnet('192.168.0.1','22',10); print tel; tel.close()"

Use python socket to check remote port is open

Python -c "import socket; s = socket.socket(); s.settimeout(10); s.connect(('192.168.0.1', 22)); "




176 views

Join our mail group. Get a free Linux account on Cloud.

Never miss a post!

Want a free Linux account?  This account can be used to login to our cloud server and practice Linux commands.

 
kamateravps.gif
topbackgroud.png

✔ Linux Commands   ✔ Linux Skills    ✔ LinuxPerformance   ✔ Linux Interview

Some articles are from the public internet. If you find your article misused or undesired here and you don't want us to display it, please let us know and we'll remove it immediately.