2

I need to verify the communication between my PC and a server. The verification would be done like this:

I would ping a server port to know if the firewall allows me to communicate with it, but this port has a service running over it, so, I don't want to use it, I just want to verify the communication with the server using that port.

tod
  • 1,539
  • 4
  • 17
  • 43
Murilo
  • 4,453
  • 5
  • 19
  • 28

2 Answers2

4

Ping does not allow you to specify a port, it only tells you if the server is responding or not, to check if a port allows communication, you can establish a TCP connection and close it after it succeed.

Steve
  • 11,696
  • 7
  • 43
  • 81
  • But would it goes well even if I have a process running over the port that I am trying to communicate ? – Murilo Apr 23 '14 at 14:58
  • 1
    @Murilo it depends, best way to find out is to try it – Steve Apr 23 '14 at 14:59
  • Ok Steve. I would create a socket to do this ? – Murilo Apr 23 '14 at 15:00
  • 1
    @Murilo yep Socket socket = new Socket(hostname, port); – Steve Apr 23 '14 at 15:01
  • So... lets use the server port 12345, if this port has a process the socket might refuse the connection. Correct ? – Murilo Apr 23 '14 at 15:08
  • 2
    @Murilo I would suggest you read about Port and connection. Most likely the socket would succeed even if theres a process running using that port if the server allows multiple connection – Steve Apr 23 '14 at 15:12
1

You can't specify a port number for a ping command, ping uses ICMP protocol (IP protocol number 1) which does not have a concept of ports to start with. Moreover, pinging you server will not tell you if the service in question is available or not.

For instance, a firewall between you and the sever can block any TCP connection yet allow pinging (you'll get false positive in this case) or vice versa (you'll get false negative in this case).

That's why many application protocols implement some king of "check health command" which you can use to check if the service (rather than a server) is available or not.

I suggest you try to connect to the service and if connection fails then you can safely assume your service is not available.

Igor Korkhov
  • 8,283
  • 1
  • 26
  • 31