コード例 #1
0
ファイル: IpV4SubnetTest.java プロジェクト: rsumbaly/netty
  @Test
  public void testBasic() throws UnknownHostException {
    IpV4Subnet subnet1 = new IpV4Subnet("10.1.1.0/24");
    IpV4Subnet subnet2 = new IpV4Subnet("10.1.1.0/255.255.255.0");
    assertTrue(subnet1.compareTo(subnet2) == 0);

    InetAddress address1 = InetAddress.getByName("10.1.1.1");
    assertTrue(subnet1.contains(address1));
  }
コード例 #2
0
 /**
  * Simple test functions
  *
  * @param args where args[0] is the netmask (standard or CIDR notation) and optional args[1] is
  *     the inetAddress to test with this IpV4Subnet
  */
 public static void main(String[] args) {
   if (args.length != 0) {
     IpV4Subnet ipV4Subnet = null;
     try {
       ipV4Subnet = new IpV4Subnet(args[0]);
     } catch (UnknownHostException e) {
       return;
     }
     if (args.length > 1) {
       try {
         System.out.println("Is IN: " + args[1] + " " + ipV4Subnet.contains(args[1]));
       } catch (UnknownHostException e) {
       }
     }
   }
 }