0

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

user291701
  • 38,411
  • 72
  • 187
  • 285

2 Answers2

7

You can get it using the InetAddress class:

InetAddress addr = InetAddress.getByName(new URL("http://www.example.com").getHost());
String ipAddress = addr.getHostAddress();
Faruk Sahin
  • 8,406
  • 5
  • 28
  • 34
  • If the destination routes me to another server though, is there any way to find out which ips I hit? For example, hitting google.com will likely route me somewhere else? – user291701 Nov 11 '12 at 21:25
0

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

Devashish Mamgain
  • 2,077
  • 1
  • 18
  • 39