@Test public void testCIDRWith8BitMask() { MachineList ml = new MachineList(CIDR_LIST2); assertFalse(ml.includes("10.241.22.255")); assertTrue(ml.includes("10.241.23.0")); assertTrue(ml.includes("10.241.23.1")); assertTrue(ml.includes("10.241.23.254")); assertTrue(ml.includes("10.241.23.255")); assertFalse(ml.includes("10.241.24.0")); assertFalse(ml.includes("10.119.103.111")); }
public boolean includes(String ipAddress) { if (all) { return true; } if ((ipAddresses != null) && ipAddresses.contains(ipAddress)) { return true; } if (cidrAddresses != null) { for(SubnetUtils.SubnetInfo cidrAddress : cidrAddresses) { if(cidrAddress.isInRange(ipAddress)) { return true; } } } if (hostNames != null) { InetAddress hostAddr; try { hostAddr = addressFactory.getByName(ipAddress); if ((hostAddr != null) && hostNames.contains(hostAddr.getCanonicalHostName())) { return true; } } catch (UnknownHostException e) { } for (String host : hostNames) { try { hostAddr = addressFactory.getByName(host); } catch (UnknownHostException e) { continue; } if (hostAddr.getHostAddress().equals(ipAddress)) { return true; } } } return false; }
MachineList { public boolean includes(String ipAddress) { if (all) { return true; } if ((ipAddresses != null) && ipAddresses.contains(ipAddress)) { return true; } if (cidrAddresses != null) { for(SubnetUtils.SubnetInfo cidrAddress : cidrAddresses) { if(cidrAddress.isInRange(ipAddress)) { return true; } } } if (hostNames != null) { InetAddress hostAddr; try { hostAddr = addressFactory.getByName(ipAddress); if ((hostAddr != null) && hostNames.contains(hostAddr.getCanonicalHostName())) { return true; } } catch (UnknownHostException e) { } for (String host : hostNames) { try { hostAddr = addressFactory.getByName(host); } catch (UnknownHostException e) { continue; } if (hostAddr.getHostAddress().equals(ipAddress)) { return true; } } } return false; } }
MachineList { public boolean includes(String ipAddress) { if (all) { return true; } if ((ipAddresses != null) && ipAddresses.contains(ipAddress)) { return true; } if (cidrAddresses != null) { for(SubnetUtils.SubnetInfo cidrAddress : cidrAddresses) { if(cidrAddress.isInRange(ipAddress)) { return true; } } } if (hostNames != null) { InetAddress hostAddr; try { hostAddr = addressFactory.getByName(ipAddress); if ((hostAddr != null) && hostNames.contains(hostAddr.getCanonicalHostName())) { return true; } } catch (UnknownHostException e) { } for (String host : hostNames) { try { hostAddr = addressFactory.getByName(host); } catch (UnknownHostException e) { continue; } if (hostAddr.getHostAddress().equals(ipAddress)) { return true; } } } return false; } MachineList(String hostEntries);  MachineList(Collection<String> hostEntries);  MachineList(Collection<String> hostEntries, InetAddressFactory addressFactory); }
MachineList { public boolean includes(String ipAddress) { if (all) { return true; } if ((ipAddresses != null) && ipAddresses.contains(ipAddress)) { return true; } if (cidrAddresses != null) { for(SubnetUtils.SubnetInfo cidrAddress : cidrAddresses) { if(cidrAddress.isInRange(ipAddress)) { return true; } } } if (hostNames != null) { InetAddress hostAddr; try { hostAddr = addressFactory.getByName(ipAddress); if ((hostAddr != null) && hostNames.contains(hostAddr.getCanonicalHostName())) { return true; } } catch (UnknownHostException e) { } for (String host : hostNames) { try { hostAddr = addressFactory.getByName(host); } catch (UnknownHostException e) { continue; } if (hostAddr.getHostAddress().equals(ipAddress)) { return true; } } } return false; } MachineList(String hostEntries);  MachineList(Collection<String> hostEntries);  MachineList(Collection<String> hostEntries, InetAddressFactory addressFactory); boolean includes(String ipAddress); @VisibleForTesting Collection<String> getCollection(); }
MachineList { public boolean includes(String ipAddress) { if (all) { return true; } if ((ipAddresses != null) && ipAddresses.contains(ipAddress)) { return true; } if (cidrAddresses != null) { for(SubnetUtils.SubnetInfo cidrAddress : cidrAddresses) { if(cidrAddress.isInRange(ipAddress)) { return true; } } } if (hostNames != null) { InetAddress hostAddr; try { hostAddr = addressFactory.getByName(ipAddress); if ((hostAddr != null) && hostNames.contains(hostAddr.getCanonicalHostName())) { return true; } } catch (UnknownHostException e) { } for (String host : hostNames) { try { hostAddr = addressFactory.getByName(host); } catch (UnknownHostException e) { continue; } if (hostAddr.getHostAddress().equals(ipAddress)) { return true; } } } return false; } MachineList(String hostEntries);  MachineList(Collection<String> hostEntries);  MachineList(Collection<String> hostEntries, InetAddressFactory addressFactory); boolean includes(String ipAddress); @VisibleForTesting Collection<String> getCollection(); static final Log LOG; static final String WILDCARD_VALUE; }