Example usage for java.net InetAddress getByName

List of usage examples for java.net InetAddress getByName

Introduction

In this page you can find the example usage for java.net InetAddress getByName.

Prototype

public static InetAddress getByName(String host) throws UnknownHostException 

Source Link

Document

Determines the IP address of a host, given the host's name.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress address = InetAddress.getByName("web.mit.edu");
    System.out.println("Name: " + address.getHostName());
    System.out.println("Addr: " + address.getHostAddress());
    System.out.println(address.isMCGlobal());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InetAddress address = InetAddress.getByName("17.16.15.14");

    boolean reachable = address.isReachable(10000);

    System.out.println("Is host reachable? " + reachable);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress addr = InetAddress.getByName("127.0.0.1");
    byte[] ipAddr = new byte[] { 127, 0, 0, 1 };
    addr = InetAddress.getByAddress(ipAddr);
    // Get the host name
    String hostname = addr.getHostName();
    // Get canonical host name
    String canonicalhostname = addr.getCanonicalHostName();

}

From source file:MainClass.java

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 {/*from  w ww.j a  v a 2 s  .  c o m*/
        System.out.println("not the same");
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    try {/*from ww w . j a  va 2 s.  co  m*/
        InetAddress ia = InetAddress.getByName("64.21.29.37");
        System.out.println(ia.getHostName());
    } catch (Exception ex) {
        System.err.println(ex);
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress addr = InetAddress.getByName("java-tips.org");
    byte[] ipAddr = addr.getAddress();

    // Convert to dot representation
    String ipAddrStr = "";
    for (int i = 0; i < ipAddr.length; i++) {
        if (i > 0) {
            ipAddrStr += ".";
        }/* www.jav  a 2 s  .c  o  m*/
        ipAddrStr += ipAddr[i] & 0xFF;
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress addr = InetAddress.getByName("java.sun.com");
    int port = 80;

    Socket socket = new Socket(addr, port);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress addr = InetAddress.getByName("java.sun.com");
    int port = 80;

    Socket socket = new Socket(addr, port, InetAddress.getByName("java2s.com"), port);
}

From source file:Main.java

static public void main(String args[]) throws Exception {
    InetAddress ia = InetAddress.getByName(args[0]);
    NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
    System.out.println(ni);/*from   ww  w . j  a va2s  .  c om*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InetAddress address = InetAddress.getByName("web.mit.edu");
    System.out.println("Name: " + address.getHostName());
    System.out.println("Addr: " + address.getHostAddress());
    System.out.println("Reach: " + address.isReachable(NetworkInterface.getByIndex(0), 0, 3000));
}