import java.net.InetAddress;Output:
import java.net.SocketException;
import java.net.UnknownHostException;
public class ServerAddress {
public static void main(String[] zero) throws SocketException {
InetAddress ServerAddress;
try{
ServerAddress= InetAddress.getByName("www.yahoo.fr");
//domain name
System.out.println("Yahoo server address = "+
ServerAddress.getHostName());
//Yahoo server IP address
System.out.println("Domain name = "+
ServerAddress.getHostName());
System.out.println("The IP address of the server Yahoo.com = "+
ServerAddress.getHostAddress());
System.out.println("The IP address of the server Yahoo.fr = "+
InetAddress.getByName("www.yahoo.fr").getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
domain name = www.yahoo.comgetHostName(): returns the machine name for this IP address.
The IP address of the server Yahoo.com = 46.228.47.115
The IP address of the server Yahoo.fr = 77.238.184.150
getHostAdress(): returns the IPv4 address of the server.
References:
Doc Oracle: InetAdress
Manipulating IP Addresses in Java
TCP Socket: Client/Server in Java
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...