找出IP地址?

时间:2012-11-11 21:09:38

标签: java android

我在android上有一个应用程序,我正在连接一个网站获取一些数据。是否有可能找到我实际连接的IP地址?我在做:

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

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

谢谢

2 个答案:

答案 0 :(得分:7)

您可以使用InetAddress类来获取它:

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

答案 1 :(得分:0)

使用这个: InetAddress address = InetAddress.getByName(“http://www.example.com”);