2013-03-08 17:10


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

Can CURL do it ? Is it possible in PHP ?

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


  • 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'];

    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




    array(6) {
      [0] =>
      string(14) ""
      [1] =>
      string(14) ""
      [2] =>
      string(14) ""
      [3] =>
      string(14) ""
      [4] =>
      string(14) ""
      [5] =>
      string(14) ""

    @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).

    点赞 评论 复制链接分享