Java examples for Network:IP Address
Getting the IP Address of a Hostname
import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public void m() { try {//from www . j a va 2 s. c o m InetAddress addr = InetAddress.getByName("java2s.com"); byte[] ipAddr = addr.getAddress(); // Convert to dot representation String ipAddrStr = ""; for (int i = 0; i < ipAddr.length; i++) { if (i > 0) { ipAddrStr += "."; } ipAddrStr += ipAddr[i] & 0xFF; } } catch (UnknownHostException e) { } } }