Java IP Address Get getIPAddress(String hostname)

Here you can find the source of getIPAddress(String hostname)

Description

Determines a host's IP address in string form.

License

LGPL

Parameter

Parameter Description
hostname The name of the network host.

Return

The IP address of the network host.

Declaration


public static String getIPAddress(String hostname) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    /**//from w  ww  . j av  a 2s . c  o  m
    * <p>Determines a host's IP address in string form.</p>
    * @param hostname The name of the network host.
    * @return The IP address of the network host.
    */

    public static String getIPAddress(String hostname) {
        String ipAddr = null;
        try {
            InetAddress ia = InetAddress.getByName(hostname);
            ipAddr = ia.getHostAddress();
        } catch (UnknownHostException e) {
        }
        return ipAddr;
    }
}

Related

  1. getIpAddress()
  2. getIPAddress()
  3. getIPAddress(boolean useIPv4)
  4. getIPAddress(final String hostName)
  5. getIPAddress(NetworkInterface e)
  6. getIpAddress(String server)
  7. getIpAddresses()
  8. getIPAddresses()
  9. getIPAddresses()