[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 548
  • Last Modified:

PHP whois array results problem

the below code returns my array ok but for some reason i cannot get the nameservers from the array.
i must be missing something simple, any suggestions ?


The result from the search is as below
[QUOTE]
Array
(
    [regyinfo] => Array
        (
            [referrer] => http://www.aunic.net
            [registrar] => AU-NIC
            [servers] => Array
                (
                    [0] => Array
                        (
                            [server] => whois.aunic.net
                            [args] => johnsons.net.au
                            [port] => 43
                        )

                )

            [type] => domain
        )

    [regrinfo] => Array
        (
            [domain] => Array
                (
                    [name] => johnsons.net.au
                    [changed] => 2008-06-30
                    [sponsor] => Melbourne IT
                    [status] => ok
                    [nserver] => Array
                        (
                            [ns1.johnsons.net.au] => 0.0.0.0
                            [ns2.johnsons.net.au] => 0.0.0.0
                        )

                )

            [owner] => Array
                (
                    [organization] => Johnsons
                    [handle] => OTHER N/A
                    [name] => Tracey Johnson
                )

            [registered] => yes
        )

    [rawdata] => Array
        (
            [0] => Domain Name:                     johnsons.net.au
            [1] => Last Modified:                   30-Jun-2008 08:16:12 UTC
            [2] => Registrar ID:                    Melbourne IT
            [3] => Registrar Name:                  Melbourne IT
            [4] => Status:                          ok
            [5] =>
            [6] => Registrant:                      Johnsons Gateway
            [7] => Registrant ID:                   OTHER N/A
            [8] => Eligibility Type:                Other
            [9] => Eligibility Name:                Johnsons Internet Services
            [10] =>
            [11] => Registrant Contact ID:           Z110566996728342
            [12] => Registrant Contact Name:         Tracey Johnson
            [13] => Registrant Contact Email:        Visit whois.ausregistry.com.au for Web based WhoIs
            [14] =>
            [15] => Tech Contact ID:                 Z110566996728342
            [16] => Tech Contact Name:               Tracey Johnson
            [17] => Tech Contact Email:              Visit whois.ausregistry.com.au for Web based WhoIs
            [18] =>
            [19] => Name Server:                     ns1.johnsons.net.au
            [20] => Name Server IP:                  0.0.0.0
            [21] => Name Server:                     ns2.johnsons.net.au
            [22] => Name Server IP:                  0.0.0.0
        )

)
[/QUOTE]

//details changed for security



include ("./phpwhois-4.1.3/whois.main.php");
 
 
$whois = new Whois();
$result = $whois->Lookup($domain_check);
 
 
$registrar = $result['regrinfo']['domain']['sponsor'];
$nameserver1 = $result['regrinfo']['domain']['nserver'][0];
$nameserver2 = $result['regrinfo']['domain']['nserver'][1];
$status = $result['regrinfo']['domain']['status'];
$owner = $result['regrinfo']['owner']['name'];

Open in new window

0
Ciphertel
Asked:
Ciphertel
  • 6
  • 2
1 Solution
 
albrieuCommented:
the problem is you are use the incorrect key

$nameserver1 = $result['regrinfo']['domain']['nserver'][ns1.johnsons.net.au];
 
but i think the key is variable and you most to parse the results in other array to get the results.



//count how nameservers contains
$total_nameservers=count($result['regrinfo']['domain']['nserver']);
$nameserver=array();
if($total_nameservers>0)
{
 foreach($result['regrinfo']['domain']['nserver'] as $key_nameserv=>$ip_nameserv)
 {
   $nameserver[]=$key_nameserv;
   
 }
}else{
  echo "no nameservers";
}
 
print_r($nameserver);

Open in new window

0
 
CiphertelAuthor Commented:
My understanding was the data was already formatted into an array and all i had to do was reference this directly
0
 
albrieuCommented:
is a key of array ns1.johnsons.net.au
for sample:
$nameserver1 = $result['regrinfo']['domain']['nserver'][ns1.johnsons.net.au];

$nameserver1 will be get the ip not the key name

if you use array_keys($result['regrinfo']['domain']['nserver'])

you get an array of keys


0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
albrieuCommented:
Try some like this code
include ("./phpwhois-4.1.3/whois.main.php");
 
 
$whois = new Whois();
$result = $whois->Lookup($domain_check);
 
 
$registrar = $result['regrinfo']['domain']['sponsor'];
 
$nameserver = array_keys($result['regrinfo']['domain']['nserver']);
 
$nameserver1 = $nameserver[0];
$nameserver2 = $nameserver[1];
 
$status = $result['regrinfo']['domain']['status'];
$owner = $result['regrinfo']['owner']['name'];}

Open in new window

0
 
CiphertelAuthor Commented:
ahh of course now i understand, thank you very much.

now i just need to work out a way to query the 'A" and 'MX' records as well.
Cheers
0
 
albrieuCommented:
your welcome

thanks for the points
0
 
albrieuCommented:
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now