Getting the IP address of the current machine using Java

后端 未结 17 1951
眼角桃花
眼角桃花 2020-11-22 02:26

I am trying to develop a system where there are different nodes that are run on different system or on different ports on the same system.

Now all the nodes create

17条回答
  •  粉色の甜心
    2020-11-22 03:21

    Use InetAddress.getLocalHost() to get the local address

    import java.net.InetAddress;
    
    try {
      InetAddress addr = InetAddress.getLocalHost();            
      System.out.println(addr.getHostAddress());
    } catch (UnknownHostException e) {
    }
    

提交回复
热议问题