Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ICMP ping in Java

3,088 views
Skip to first unread message

Peter

unread,
Mar 12, 1999, 3:00:00 AM3/12/99
to

Hi all,

I read from somewhere that ICMP ping cannot be implemented in Java.
Which means one cannot write a ping program in Java using ICMP protocol.

How true is the statement??? Even not with the latest JDK 1.2 version???

Thank you,
Peter


Michael A. Margozzi

unread,
Mar 13, 1999, 3:00:00 AM3/13/99
to
It is not possible without native methods.
You do NOT have access to IP, just Sockets.

You can do it if you are willing to write native methods for each and
every platform you want to support.

Mike Margozzi


Peter van der Linden

unread,
Mar 13, 1999, 3:00:00 AM3/13/99
to
>I read from somewhere that ICMP ping cannot be implemented in Java.
>Which means one cannot write a ping program in Java using ICMP protocol.

That is correct. The Java FAQ explains why and presents some
close alternatives. The FAQ is at

http://www.afu.com

Peter

unread,
Mar 14, 1999, 3:00:00 AM3/14/99
to

Thanks Peter and Michael for the answer.

Following is what I read from
http://www.davidreilly.com/java/java_network_programming/#3.5
"Java includes support for UDP and TCP sockets. PING requires support for
the
Internet Control Message Protocol (ICMP). Your only choice (at the moment),
is to use native code, or to use java.lang.Runtime to execute an external
ping application. You won't be able to develop a 100% Pure implementation."


So is there any example on ping using the native code or java.lang.Runtime
that I can refer to???

Does using the native code or java.lang.Runtime mean that ICMP protocol
will not be used.

Thanks again,
Peter


Michael A. Margozzi wrote in message <36EAAA21...@garlic.com>...

Ayyaparaju Ganapathiraju

unread,
Mar 15, 1999, 3:00:00 AM3/15/99
to
Just wondering if it is possible to fake ping by using "echo" server which
runs on well known port# 7. If the purpose is to know that the target host
is alive, this might work.

Here is a sample code that opens a socket on port 7 and writes a string and
reads it back. The target host name is passed on command line.

import java.net.*;

public class JPing
{
private static Socket s = null;
private static BufferedWriter os = null;
private static BufferedReader is = null;

public static void main (String argv[])
{
char str[] = new char [10];
try
{
s = new Socket (argv[0], 7);

is = new BufferedReader (new InputStreamReader
(s.getInputStream()));
os = new BufferedWriter (new OutputStreamWriter
(s.getOutputStream()));
os.write ("Hello1", 0, 6); os.flush();
is.read (str, 0, 6);
System.out.println (argv[0] + " IP = " +
s.getInetAddress());
System.out.println ("Received: " + str);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}

Peter <pete...@hotmail.com> wrote in message
news:36ed0...@news.cyberway.com.sg...

James Driscoll

unread,
Mar 22, 1999, 3:00:00 AM3/22/99
to
On Mon, 15 Mar 1999 10:18:18 -0500, "Ayyaparaju Ganapathiraju"
<agr...@cybertours.com> wrote:

>Just wondering if it is possible to fake ping by using "echo" server which
>runs on well known port# 7. If the purpose is to know that the target host
>is alive, this might work.

Only if the target host is running echo on port 7, a chancy
proposition at best.

Jim


0 new messages