NetworkUtils { @Nullable public String getLocalHostName() { try { return InetAddress.getLocalHost().getHostName(); } catch (final UnknownHostException e) { LOG.log(Level.WARNING, e.toString()); } return null; }  boolean isUsable(@Nullable final NetworkInterface netif); boolean hasIPv4Address(@Nullable final NetworkInterface netif); String getNetworkInterfaceInfo(@Nullable final NetworkInterface netif); String getIPv4Addresses(@Nullable final NetworkInterface netif); String getIPv4Addresses(@Nullable final NetworkInterfaceInfo networkInterfaceInfo); String getMacAddress(@Nullable final NetworkInterface netif); @Nullable NetworkInterface getUpdatedNetworkInterface(@Nullable final NetworkInterface origNetIf); boolean sameNetworkInterface(@Nullable final NetworkInterface netIf1,
                                        @Nullable final NetworkInterface netIf2); @Nullable NetworkInterface findFirstUsableNetworkInterface(); @Nullable Enumeration<NetworkInterface> getNetworkInterfaces(); List<NetworkInterfaceInfo> getUsableNetworkInterfaces(); @Nullable String getLocalHostName(); @Nullable NetworkInterface getNetworkInterfaceByName(final String name); static final int IPTOS_RELIABILITY; }
@Test public void testGetLocalHostName() { try { final InetAddress localHostAddress = InetAddress.getLocalHost(); final String localHostName = networkUtils.getLocalHostName(); assertNotNull("Name of localhost should not be null", localHostName); final InetAddress addressByName = InetAddress.getByName(localHostName); assertEquals("The addresses should be equal", localHostAddress, addressByName); } catch (final UnknownHostException e) { System.err.println("Could not get localhost - aborting test: " + e.toString()); } }