【问题标题】:Find out IP address?找出IP地址?
【发布时间】:2012-11-11 21:09:37
【问题描述】:

我在 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(?));

谢谢

【问题讨论】:

标签: java android


【解决方案1】:

您可以使用InetAddress 类获取它:

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

【讨论】:

  • 如果目的地将我路由到另一台服务器,有没有办法找出我点击了哪些 ip?例如,点击 google.com 可能会将我转到其他地方?
【解决方案2】:

只需使用这个: InetAddress 地址 = InetAddress.getByName("http://www.example.com");

【讨论】:

    猜你喜欢
    • 2017-03-20
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2012-11-17
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多