8

Just as you'd ping an IP of to a server to check if it is up, can we also check if, on that running server, a port is active/open?

this just comes from my head,but can you be more specific in your ping statement?

 `ping 127.0.0.1:7004`

I know this command is not allowed, but is there a way to check for this in Linux and Windows?

5 Answers 5

9

If you are willing and able to install software, you can use nmap

nmap -p 7004 127.0.0.1

Or if it is internet facing, use a web service such as http://www.yougetsignal.com/tools/open-ports/

6

That depends upon your access to system (client or server), You can use either of two options,

  1. Server side you can use netstat -an to check which ports are listening
  2. From outside use just telnet host port, if it is not working on linux machines try telnet host:port.
3
  • Don't use code formatting for text that isn't code.
    – user207421
    Commented Jun 4, 2015 at 5:23
  • @EJP I selected only relevant code but it took whole line.. Even I didn't like it at first place.. I think either code formatting has issues with bullets or I did something bad. Anyways thanks for formatting it..
    – Amit
    Commented Jun 4, 2015 at 5:26
  • Thank you, I am on the server side and netstat is doing exactly what I wanted :) Commented Jun 4, 2015 at 6:47
2

As telnet is disabled by most corporate customers, i found that powershell command on windows machines for TCP quite useful: New-Object System.Net.Sockets.TcpClient("server", port)

2
  • thank you. Though this one expects me to know the port number... but it is a command I did not know if. Thanks Commented Feb 10, 2022 at 10:17
  • 1
    Yes you are welcome, that was part of the question with knowing the port and checking whether it is open. If you are on the server side and want to check open ports on windows you can use the "resource monitor" > network tab> listening ports Commented Feb 11, 2022 at 11:33
0

For TCP-Ports you can simple use telnet or nc to establish a connection. If it succeeds, the port is open.

But as UDP is stateless you cannot check that simple for an open port. You have to know which service is behind this port and know how to send a valid packet so you get an answer.

0
$ docker run -it --rm --network host networkstatic/nmap localhost

Not the answer you're looking for? Browse other questions tagged or ask your own question.