tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons Http Client > How to check IP Address Type

How to check IP Address Type 

Commons Http Client is a HTTP agent implementation in java supporting client-side authentication, HTTP state management and HTTP connection management. This requires the libraries httpclient-4.1.2.jar, httpcore-4.1.2.jar, httpmime-4.1.2.jar, httpclient-cache-4.1.2.jar, commons-codec.jar and commons-logging-1.1.1.jar to be in classpath. The following example shows how to verify whether the given IP is IPv4 or IPv6.

File Name  :  
com/bethecoder/tutorials/commons_httpclient/IPAddressTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_httpclient;

import org.apache.http.conn.util.InetAddressUtils;

public class IPAddressTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    boolean isIPv4 = InetAddressUtils.isIPv4Address("192.168.1.8");
    System.out.println(isIPv4);
    
    isIPv4 = InetAddressUtils.isIPv4Address("127.0.0.1");
    System.out.println(isIPv4);
    
    
    boolean isIPv6 = InetAddressUtils.isIPv6Address("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210");
    System.out.println(isIPv6);
    
    isIPv6 = InetAddressUtils.isIPv6Address("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
    System.out.println(isIPv6);
    
    isIPv6 = InetAddressUtils.isIPv6Address("1080:0:0:0:8:800:200C:417A");
    System.out.println(isIPv6);
    
    isIPv6 = InetAddressUtils.isIPv6Address("1080::8:800:200C:417A");
    System.out.println(isIPv6);
    
  }

}
   

It gives the following output,
true
true

true
true
true
true



 
  


  
bl  br