【问题标题】:IP to URL to AddressIP 到 URL 到地址
【发布时间】:2017-07-22 03:14:51
【问题描述】:

我想要: 如果输入:<IP-Address> -> 输出(准确!!!):www.example.com

问题:如果我只有一个网站的 IP 地址 (51.254.201.70) 并且想找出它是哪个网站,我只会得到这样的信息:70.ip-51-254-201 。欧盟。我想得到确切的 www.webmoney.ru

我发现了什么:

package PACK;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPtoHost4 {

  // Input:www.webmoney.com -> Output: All IP-Adresses of this Page
public static void main(String[] args) throws UnknownHostException {


        for (InetAddress addr : InetAddress.getAllByName("www.webmoney.ru")) {

            System.out.println(addr.getHostAddress() + " : " + getHost(addr));
        }

    // Output:
    // 5.199.142.158 : www.webmoney.ru
    // 51.254.201.70 : www.webmoney.ru
    // 62.210.115.140 : www.webmoney.ru
    // 88.99.82.144 : www.webmoney.ru

    // Input:All-IPs -> Output: hostnames
    String[] ips = { "5.199.142.158", "51.254.201.70", "62.210.115.140", "88.99.82.144" };
    for (String i : ips) {
        InetAddress ip = null;
        ip = InetAddress.getByName(i);
        System.out.println(getHost(ip));
    }
    //  Output:
    // z158.zebra.servdiscount-customer.com
    // 70.ip-51-254-201.eu
    // 62-210-115-140.rev.poneytelecom.eu
   // static.144.82.99.88.clients.your-server.de

}

static String getHost(InetAddress ip) {
    String hostName = "";
    hostName = ip.getHostName();

    return hostName;

}

}

【问题讨论】:

  • 您获得的那些域可能是 ips 的正确域。您可能会假设您正在查询的域正在重定向您。除此之外,“webmoney”和“.ru”看起来很可疑,所以要小心。
  • 一个IP地址可以有多个域名(virtual hosting)。
  • 嗨。我只有 Wireshark 的 IP 地址。我想找出我的用户从我的服务器访问的真正的 HTML 网站(DNS 服务器和域对我来说并不感兴趣)。

标签: java ip ip-address hostname


【解决方案1】:

我有一个解决方案,我将如何找出发送 HTML 代码 301/302 以进行重定向的网站。但如果我得到 HTML Code 200,我只能识别出一个 主机名。我想确定网站的全名。

查看示例:

public static void main(String[] args) throws IOException {

    String ip = "78.129.242.2";
    URL myURL = new URL("http://" + ip);

    HttpURLConnection con = (HttpURLConnection) myURL.openConnection();
    con.setInstanceFollowRedirects(false);
    con.connect();

    // HTML-Code from a website
    int responseCode = con.getResponseCode();
    System.out.println(responseCode);

    // HTTP 200 OK
    if (responseCode == 200) {
        InetAddress addr = null;
        addr = InetAddress.getByName(ip);
        String host = addr.getHostName();
        System.out.println(host);
    }

    // HTTP 301 oder 302 redirect
    else if (responseCode == 301 || responseCode == 302) {
        String location = con.getHeaderField("Location");
        System.out.println(location);
    } else {
        System.out.println("Bad Web Site" + " ResponceCode: " + responseCode);
    }
}

【讨论】:

    猜你喜欢
    • 2018-04-05
    • 2021-12-05
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 2010-12-13
    • 2014-12-02
    • 2013-02-27
    • 1970-01-01
    相关资源
    最近更新 更多