InetAddressParser { public boolean matches(String provIpAddress, String provHostName) { InetAddressParser iap = new InetAddressParser(provIpAddress); if (!iap.isHostAddress()) return false; byte [] myaddr = getHostAddress(); byte [] ipaddr = iap.getHostAddress(); if (m_hostAddrOnly) { for(int i=0; i < 4; i++) { if(myaddr[i] != ipaddr[i]) return false; } } try { String hostName = InetAddress.getByName(m_addrStr).getHostName(); if (hostName.equals(provHostName)) return true; return false; } catch (UnknownHostException e) { return false; } } InetAddressParser(String ipaddress); boolean parse(); String getAddressElement(byte [] ipaddr, int offset, AddressElement ae); int getPrefixLen(); boolean isHostAddress(); boolean isNetworkAddress(); byte [] getHostAddress(); boolean matches(String provIpAddress, String provHostName); boolean matches(String address); static final byte[] intToAddressBytes(int nCompactAddress); static final String intToAddressString(int nCompactAddress); static final InetAddress intToAddress(int nCompactAddress); static final int addressToInt(byte[] addr); static final int addressToInt(InetAddress addr); static final int addressToInt(String addr);  }
@Test public void testmatches(){ InetAddressParser parser = new InetAddressParser("10.5.6.8"); assertTrue(parser.matches("10.5.6.8")); }
@Test public void testNotmatches(){ InetAddressParser parser = new InetAddressParser("10.5.6.8"); assertFalse(parser.matches("10.5.6.7")); }