Hi,
I got this example from Real Gagnon's website at http://www.rgagnon.com :
Ping a server
It's not possible to really "ping" a machine to check if it's alive or not
(it's a long story, but to keep it short I will just say that the Socket
class is not low-level enough for that operation). But we can emulate a
ping by talking the "echo port". On a server, the echo port is always port
7. We write a string to that port and the server will echo the string.
import java.io.*;
import java.net.*;
public class PseudoPing {
public static void main(String args[]) {
try {
Socket t = new Socket(args[0], 7);
DataInputStream dis = new DataInputStream(t.getInputStream());
PrintStream ps = new PrintStream(t.getOutputStream());
ps.println("Hello");
String str = is.readLine();
if (str.equals("Hello"))
System.out.println("Alive!") ;
else
System.out.println("Dead or echo port not responding");
t.close();
}
catch (IOException e) {
e.printStackTrace();}
}
}
HTH,
Greg.
Shawn Quinn <[EMAIL PROTECTED]> on 2002/09/18 01:42:33 PM
Please respond to "JDJList" <[EMAIL PROTECTED]>
To: "JDJList" <[EMAIL PROTECTED]>
cc:
Subject: [jdjlist] RE: Ping utilty - through Java
I believe java.net.InetAddress.getByName(String host) should do what you
need.
Hope this helps,
-Shawn
-----Original Message-----
From: Nahid, Nazneen (CORP, Consultant)
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 18, 2002 1:35 PM
To: JDJList
Subject: [jdjlist] Ping utilty - through Java
Hi ,
Problem :- A given set of server HostName. Have to write a program inb Java
to get there IPAddress.
( the feature that is obtained my ping utility).
Any help soon would be appreciated.
Thanks & Regards,
Nazneen Nahid
GECIS -Tata Consultancy Services
* Phone 518-612-6826 DialComm *8-222-6826
* E-Mail mailto:[EMAIL PROTECTED]
Visit TCS at: http://www.tcs.com
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm