import java.net.InetAddress;getHostName () < / span>: إرجاع اسم الجهاز لعنوان IP هذا.
import java.net.SocketException ؛
import java.net.UnknownHostException;
من الفئة العامة ServerAddress {
الفراغ العام الثابت الرئيسي (السلسلة [] صفر) يلقي SocketException {
InetAddress ServerAddress ؛
try{
ServerAddress= InetAddress.getByName("www.yahoo.fr");
//domain name
System.out.println ("عنوان خادم Yahoo = "+
ServerAddress.getHostName());
//Yahoo server IP address
System.out.println ("اسم المجال = "+
ServerAddress.getHostName());
System.out.println("عنوان IP للخادم Yahoo.com = "+
ServerAddress.getHostAddress());
System.out.println("عنوان IP للخادم Yahoo.fr = "+
InetAddress.getByName("www.yahoo.fr").getHostAddress());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
< / pre> الإخراج:
< pre class = "prettyprint lang-java" > اسم المجال = www.yahoo.com
عنوان IP للخادم Yahoo.com = 46.228.47.115
عنوان IP للخادم Yahoo.fr = 77.238.184.150
Please disable your ad blocker and refresh the window to use this website.