dpftppc9674
dpftppc9674
2013-03-08 17:10

如何获取网站的所有IP地址?

Is there any way to get a given website all IP addresses?

Can CURL do it ? Is it possible in PHP ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • duancao2082 duancao2082 8年前

    Use dns_get_record, like this:

    $all_records = dns_get_record('example.com');
    $ips = array();
    foreach ($all_records as $r) {
        if ($r['type'] == 'A') {
            $ips[] = $r['ip'];
        }
        if ($r['type'] == 'AAAA') {
            $ips[] = $r['ipv6'];
        }
    }
    var_export($ips);
    

    gethostbynamel also provides a simplified interface if you're only interested in IPv4 addresses.

    Note that due to the limited response size and geographical preferences, you may need to ask this query multiple times from multiple locations to get all (or most) addresses of a well-frequented domain such as google.com.

    点赞 评论 复制链接分享
  • dongtang6775 dongtang6775 8年前

    PHP has a function for this: gethostbynamel()

    The function performs a DNS query and returns the resulting IPs

    Example:

    var_dump(gethostbynamel('google.com'));
    

    Output

    array(6) {
      [0] =>
      string(14) "173.194.70.139"
      [1] =>
      string(14) "173.194.70.113"
      [2] =>
      string(14) "173.194.70.100"
      [3] =>
      string(14) "173.194.70.138"
      [4] =>
      string(14) "173.194.70.102"
      [5] =>
      string(14) "173.194.70.101"
    }
    

    @MEznati About load balancing:

    There are several ways of Load Balancing. Google for example uses DNS based load balancing, that's why I took it for example. If a form of internal load balancing is being used - meaning that the load balancer has 1 external IP and redirects requests to internal servers - you'll not being able to get those internal (private) IPs (that's by design).

    点赞 评论 复制链接分享

为你推荐