Reputation: 39671
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
Reputation: 2097
just use this: InetAddress address = InetAddress.getByName("http://www.example.com");
Upvotes: 0
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