user291701
user291701

Reputation: 39671

Find out IP address?

I've got an app on android, and I'm connecting to a website for some data. Is it possible to find out the IP address that I'm actually connecting to? I'm doing:

HttpUriRequest request = new HttpGet("http://www.example.com");
DefaultHttpClient client = new DefaultHttpClient(params);
HttpResponse response = client.execute(request);

println("You connected to: " + response.getIpAddress(?));

Thank you

Upvotes: 0

Views: 316

Answers (2)

Devashish Mamgain
Devashish Mamgain

Reputation: 2097

just use this: InetAddress address = InetAddress.getByName("http://www.example.com");

Upvotes: 0

Faruk Sahin
Faruk Sahin

Reputation: 8726

You can get it using the InetAddress class:

InetAddress addr = InetAddress.getByName(new URL("http://www.example.com").getHost());
String ipAddress = addr.getHostAddress();

Upvotes: 7

Related Questions