📄 net.java
字号:
package intnet;
import java.net.*;
public class Net {
public static void main (String args[]) {
InetAddress myIP = null; //声明IP地址对象变量
try {
myIP = InetAddress.getLocalHost(); //获得本级IP地址
//下面的语句显示了获得指定主机名的IP地址的方法
//myIP = InetAddress.getByName("java.sun.com");
System.out.println("HostAddress is "+myIP.getHostAddress());
System.out.println("HostName is "+myIP.getHostName());
}catch(UnknownHostException e){
//忽略异常
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -