NetUtils { public static String getHostAddress(){ return getInetAddress().map(i->i.getHostAddress()).orElse(LOCAL_IP); } private  NetUtils(); static String getHostAddress(); static String getHostName(); static InetAddress getInetAddress(String address, InetAddress def); static Optional<InetAddress> getInetAddress(); static String getHost(String url); static final String LOCAL_IP; }
@Test public void testGetHostAddress(){ String address = NetUtils.getHostAddress(); System.out.println("address:"+address); address = NetUtils.getHostName(); System.out.println("address:"+address); }