用idea查看本机IP

直接上代码:

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
 

上一篇:组播示例


下一篇:Java网络编程