Intro
To get IP address of a host, you can use the InetAddress class. By calling getHostAddress() method, you can get an IP address of the host.
Example
package com.freesamplecode.java.networking; import java.net.InetAddress; import java.net.UnknownHostException; public class GetIPAddressByHost { public static void main(String[] args){ try { InetAddress host = InetAddress.getByName("free-samplecode.blogspot.com"); System.out.println("IP Address : "+host.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); } } }
Ouput
IP Address : 74.125.200.132
0 comments: