What port does ping use?
This seems like a simple question, but I cannot find a definitive answer.
Linux manual page for ping mentions an ECHO_REQUEST datagram:
"Ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams (``pings'') have an IP and ICMP header, followed by a ``struct timeval'' and then an arbitrary number of ``pad'' bytes used to fill out the packet."
I searched the include directory and found this C preprocessor define:
#define ICMP6_ECHO_REQUEST 128
I also found this in a document someone gave me:
* 128/tcp GSS X License Verification
* 128/udp GSS X License Verification
And, finally, in the RFC 1060 specification, I found this:
7 ECHO Echo [95,JBP]
What I'm trying to do is write a ping program in Java, if that's at all possible. I know that the standard ping uses the ICMP (Internet Control Message Protocol) which is a low-level network administration protocol not supported in Java nor in Microsoft's Winsock. ICMP on Win32 is provided by an unsupported and undocumented library icmp.dll. I also know that it's sending an ICMP datagram.
However, all ping does is simply send a message to the host and report if it arrived. That takes all of three lines of code in Java. But, it's not working for most of the hosts I've tried where the standard ping program does. I keep getting an exception of "Connection refused" every time.
These are the port numbers I've tried:
7 Echo service
There may be some other reason why my Java ping program fails where the standard ping succeeds, but trying every possible port number with a range of hosts is impractical. By knowing definitively what port ping uses, I can eliminate the other factors.
I'm asking this question in the Java area because I think the answer would benefit this community most, not because I think a Java expert would necessarily know the answer (I may be wrong, if so I apologize). So, I've referenced this question in several other topic areas.