直接上代码:
public class InterTest {
public static void main(String[] args) {
try {
InetAddress localHost = InetAddress.getLocalHost();
System.out.println(localHost);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
执行结果:
DESKTOP-J4ALVDC/192.168.0.105
Process finished with exit code 0