Here you can find the source of getIPAddress(String hostname)
Determines a host's IP address in string form.
Parameter | Description |
---|---|
hostname | The name of the network host. |
public static String getIPAddress(String hostname)
//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; } }