import java.net.InetAddress;输出:
import java.net.UnknownHostException;
public class Clientaddress {
public static void main(String[] args) {
String hostname;
字符串地址IPLocale;
try{
InetAddress inetadr = InetAddress.getLocalHost();
//机器名
hostname = (String) inetadr.getHostName();
System.out.println(计算机名称 = ”+主机名);
//网络上的IP地址
IPLocale address = (String) inetadr.getHostAddress();
System.out.println(本地 IP 地址 = ”+IPlOcale)
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
机器名称 = VAIO-VAIO参考:
本地 IP 地址 = 192.168.1.101
Please disable your ad blocker and refresh the window to use this website.