2007年12月30日日曜日

[Java>Original]Useful Network Utility(Utility to check Netmask, Network address)

Useful Network Utility to calculate CIDR address and check network address.

References
  • about CIDR
    http://h50146.www5.hp.com/products/software/oe/tru64unix/manual/v51a_ref/HTML/MAN/MAN7/0127____.HTM
  • Sample Source code
    http://osdir.com/ml/jakarta.james.devel/2003-02/msg00469.html
    http://lenya.apache.org/apidocs/1.2/org/apache/lenya/net/InetAddressUtil.html
Original Source Code
  • http://groups.google.com/group/taapps-sourcecode-libraries/web/Net.java
Check Utility to contain the ip address into the specified CIDR network address.
  • Description
    Network address check utility
    Check whether the specified ip address is into the CIDR network address(format like "192.168.1.0/24") or not.
    This method has 2 arguments, one is String object contains CIDR network address, other is IP address you want to check.
  • Sample
    //for example, my ip address is 192.168.1.3
    //check whether my ip address "192.168.1.3" is into the network 192.168.1.0/24 or not
    boolean compare=Net.containIp("192.168.1.0/24","192.168.1.3");
    if(compare){
    //contain the specified ip address "192.168.1.3" into network "192.168.1.0/24"
    }
Check Utility 2 to contain the ip address into the specified CIDR network list.
  • Description
    Check whether the specified ip address is into the CIDR network address list or not.
    This method has 2 arguments, one is List object contains CIDR network addresses, other is IP address you want to check.
  • Sample
    List networkList=new ArrayList();
    networkList.add("192.168.1.0/24");
    networkList.add("192.168.2.0/24");
    networkList.add("192.168.3.0/24");
    networkList.add("192.168.4.0/24");
    boolean compare2=Net.containIp(networkList,"192.168.2.200");
    if(compare){
    //contain the specified ip address "192.168.1.3" into network "192.168.1.0/24"
    }

0 件のコメント: