What is the associated IP address
Hi All,
I want to know, what is the associated IP address to access
"localHost" using Mac OS 9.2.2 as it is in Windows XP?
When I use "127.0.0.1" in Windows in the below program, the
result is the word "localhost".
When I use "127.0.0.1" in the Mac in the below program
the result is the word "unknown".
My distant goal is to get a programs EchoClient.java and
EchoServer.java to work on the Mac. Now if I start the
EchoServer/EchoClient with the "127.0.0.1" address
it wants to go out on the net and starts looking
and never returns (it hangs). Failure, since it does
not know "localHost " or "127.0.0.1". Is there
a work around?
TIA
bH
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IPtoDNS
{
/**
* Find the DNS name associated with an IP
*
* @param args not used
* Downloaded from Roedy Green's Library
*/
public static void main ( String[] args )
{
try
{
InetAddress[] addresses = InetAddress.getAllByName
("127.0.0.1" /* ip or DNS name */ );
for ( int i=0; i<addresses.length; i++ )
{
String hostname = addresses[i].getHostName();
System.out.println( hostname );
}
}
catch ( UnknownHostException e )
{
System.out.println( "unknown host" );
}
}
}