Compare two IP address in Java

Description

The following code shows how to compare two IP address.

Example


   /*from   www. j a  va2 s  .com*/

import java.net.InetAddress;

public class Main {

  public static void main(String args[]) throws Exception {

    InetAddress ca = InetAddress.getByName("www.google.ca");
    InetAddress com = InetAddress.getByName("www.google.com");
    if (ca.equals(com)) {
      System.out.println("same");
    } else {
      System.out.println("not the same");
    }
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode