0

The aim of my project is to create a bulk WHOIS checker which outputs select information from multiple whois records.

I think I'm quite close to finishing it there is just an annoying bug which I can't figure out. (It's probabaly something really simple)

My code is as follows;

    $domain = explode("\r\n", $domains);

    print_r($domain);
    echo "<br /><br />";


    foreach ($domain as $item) {

        fwrite($fp, $item . "\r\n");

        while (!feof($fp)) {
            $lookup .= fread($fp, 8192);
        }

        $value = explode("\r\n\r\n", $lookup);
                    $whois_data = array();


        foreach ($value as $values) {
            $details = explode(":\r\n", $values, 2);
            $whois_data[trim($details[0])] = $details[1];
        }

        echo "Show WHOIS data for " . $item . "<br />";
        print_r($whois_data);
        unset($whois_data);
        echo "<br /><br />";
    }

$domains is a textarea box with one domain per line, my output from this PHP is as follows;

Array ( [0] => madeupdomainname.co.uk [1] => anothermadeupdomain.co.uk )

Show WHOIS data for madeupdomainname.co.uk

Array ( [Domain name] => madeupdomainname.co.uk [Registrant] => Made Up Inc. [Registrant type] => Unknown [Registrant's address] => 123 Fake Road City UK [Registrar] => Made Up Inc. t/a Made Up [Tag = MADEUP] URL: madeupdomainname.co.uk [Relevant dates] => Registered on: 14-Feb-1929 Renewal date: 11-Feb-2023 Last updated: 12-Feb-2031 [Registration status] => Registered until renewal date. [Name servers] => ns1.madeupdomainname.co.uk ns2.madeupdomainname.co.uk ns3.madeupdomainname.co.uk ns4.madeupdomainname.co.uk [WHOIS lookup made at 01:09:24 08-Dec-2011] => [-- This WHOIS information is provided for free by Nominet UK the central registry for .uk domain names. This information and the .uk WHOIS are:] => [Copyright Nominet UK 1996 - 2011.] => [You may not access the .uk WHOIS or use any data from it except as permitted by the terms of use available in full at nominet.org.uk/whois, which includes restrictions on: (A) use of the data for advertising, or its repackaging, recompilation, redistribution or reuse (B) obscuring, removing or hiding any or all of this notice and (C) exceeding query rate or volume limits. The data is provided on an 'as-is' basis and may lag behind the register. Access may be withdrawn or restricted at any time.] => )

Show WHOIS data for anothermadeupdomain.co.uk

Array ( [Domain name] => madeupdomainname.co.uk [Registrant] => Made Up Inc. [Registrant type] => Unknown [Registrant's address] => 123 Fake Road City UK [Registrar] => Made Up Inc. t/a Made Up [Tag = MADEUP] URL: madeupdomainname.co.uk [Relevant dates] => Registered on: 14-Feb-1929 Renewal date: 11-Feb-2023 Last updated: 12-Feb-2031 [Registration status] => Registered until renewal date. [Name servers] => ns1.madeupdomainname.co.uk ns2.madeupdomainname.co.uk ns3.madeupdomainname.co.uk ns4.madeupdomainname.co.uk [WHOIS lookup made at 01:09:24 08-Dec-2011] => [-- This WHOIS information is provided for free by Nominet UK the central registry for .uk domain names. This information and the .uk WHOIS are:] => [Copyright Nominet UK 1996 - 2011.] => [You may not access the .uk WHOIS or use any data from it except as permitted by the terms of use available in full at nominet.org.uk/whois, which includes restrictions on: (A) use of the data for advertising, or its repackaging, recompilation, redistribution or reuse (B) obscuring, removing or hiding any or all of this notice and (C) exceeding query rate or volume limits. The data is provided on an 'as-is' basis and may lag behind the register. Access may be withdrawn or restricted at any time.] => )

As you can see it's grabbing the WHOIS data from the first domain correctly but then ignoring the second domain and just re using the first domains WHOS information which is really bugging me. Any suggestions?

Thanks.

Hairzo
  • 107
  • 1
  • 2
  • 10
  • 1
    Where do you clear the value of `$lookup` between runs? Do you need to? – sarnold Dec 08 '11 at 01:26
  • Hey, I didn't think of clearing $lookup so I have added an unset($lookup); directly after unset($whois_data);. With this in place the first query retruns the correct WHOIS information but the second one returns nothing. e.g Array ( [] => ) – Hairzo Dec 08 '11 at 01:52
  • Two very important notes: 1) Most registries, including Nominet (`.co.uk`), prohibit bulk access and will block your IP if you start hitting them repeatedly. 2) Your assumptions about the format of the WHOIS response (specifically, that you can `explode()` on `:`) are incorrect. There is no standard response format. –  Dec 08 '11 at 02:05
  • Hey duskwuff, you are allowed to make 1000 queries per day per IP to nominet, as this will be an internal project this will be fine for our use. The format for exploding works for the data I need as for the trailing data at the end which doesnt explode well, I kill that off. – Hairzo Dec 08 '11 at 02:07
  • Once you've read an EOF on your `$fp`, are you sure you're still allowed to `fwrite()` into it? Check the `fwrite()` call for an error return. – sarnold Dec 08 '11 at 02:14
  • Thanks for the reply sarnold, I have it all working now thanks to duskwuff enlighening me that you can only make one query per connection, so on my foreach loop I make a new connection to the server which has solved the problem. – Hairzo Dec 08 '11 at 02:28

1 Answers1

1

The WHOIS protocol only allows for one request per connection. You must open a new connection for each request.

  • Yes! Thank you that has fixed my problem, I now open a new connection for each domain in the list. Thank you very much! – Hairzo Dec 08 '11 at 02:14