Solved

Php whois API extract raw data fields from array

Posted on 2009-05-05
34
1,334 Views
Last Modified: 2013-12-12
I'm in need of a little help here, have got my head on backwards and cannot work out how to get the results I want.

I'm using phpwhois api to query a DB of domains I host. I basically want to extract the relevant information and write it back to the database.

The problem i have is the raw data output varies in format between tlds so i need some sort of matching to grab the records i need to write back for different tlds.

My end result i'm hoping to achieve is have a list of all domains and where they are registered, who they are registered too. in the case of a ".com" the expiry date and eventually MX records and "A" Records

ANy help for this newb appreciated.
<?

include ("./phpwhois-4.1.3/whois.main.php");

 

$nameserver1 = "";

$nameserver2 = "";

$registrar = "";

$status = "";

$owner = "";

$registrant = "";

 

 

$username = "root";

$password = "letmein";

$hostname = "10.0.2.13";

 

	

$dbh = mysql_connect($hostname, $username, $password)

	or die("Unable to connect to MySQL");

 

 

mysql_select_db("domains", $dbh);

 

 

 

 

// Select one domain from the database that hasn't been checked yet

$sql = "SELECT domainName from domains ORDER BY lastChecked ASC LIMIT 1";

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$domain_check = $row[0];

 

 

if(mysql_num_rows($result) == 0){

    die("No domains found in the database.");

print "No domains found in the database.";

}

 

 

 

$whois = new Whois();

$result = $whois->Lookup($domain_check);

 

if (isset($result['regrinfo']['registered']))

	{

 

		$status = $result['regrinfo']['registered'];

 

 

if (isset($result['regrinfo']['domain']['nserver']))

				{

				$nserver = $result['regrinfo']['domain']['nserver'];

 

				if (is_array($nserver))

					{

 

$nameserver = array_keys($result['regrinfo']['domain']['nserver']);

$nameserver1 = $nameserver[0];

$nameserver2 = $nameserver[1];

}

   }

 

if (isset($result['regrinfo']['domain']))

				{

 

$registrar = $result['regrinfo']['domain']['sponsor'];

$owner = $result['regrinfo']['owner']['organization'];

$status = $result['regrinfo']['domain']['status'];

	}

 

 

print_r ($result);

 

// Update domain information in database

$sql = "UPDATE domains SET status='".$status."',registrar='".$registrar."',registrant='".$owner."',nameserver1='".$nameserver1."',nameserver2='".$nameserver2."',lastchecked=NOW() WHERE domainName='".$domain_check."'";

//mysql_query($sql);

 

	

 

mysql_close($dbh);

?>

Open in new window

domains.txt
0
Comment
Question by:Ciphertel
  • 17
  • 16
34 Comments
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
If you increase points awarded you would probably get more Es to solve.

Also what did you want the script to do and what is it doing now? More detail please
0
 

Author Comment

by:Ciphertel
Comment Utility
The output varies between tlds, for the most part it grabs all the data i need i just wish to query those further if they are delegated to my DNS servers and grab the MX records and A records and populate my database further.

The existing script does grab most of the data but say i have a .com or a strange one like .biz. the whois data is different and may not neccesarilly grab all the information i need.
0
 

Author Comment

by:Ciphertel
Comment Utility
Additional points awarded for completion of script
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
1.) Please define tIds.

2.) Can you give an example of the differences between .com and .biz?

3.) In the case the script doesn't grab all of the information; what do you suggest?

Thanks
0
 

Author Comment

by:Ciphertel
Comment Utility
if the search is for a ".com" domain then the returned array data is in a different format than say a ".com.au" domain.

With the existing code i can pretty much have all the fields returned as required to populate my sql database. (Pls refer to attached sql file to determine fields required) however if the returned data does not match my exisiting variables then i get array()  in the database instead of the relevant information.

The script would need to match expressons to determine the fields values i require and where they are assigned in the array. that way all information could be parsed to the database.

A secondary script or function would then be run to query the dns servers to determine host records, this would be only against my own servers to see an overall picture of demographics.
0
 

Author Comment

by:Ciphertel
Comment Utility
Attached are two text files containg the results of the query.
If we concentrate on the rawdata and do some sort of regexp to match the relevant fields i require then save them back to the database.

I think that would be the easiest way.

Then an additional script to query the database based on search criteria matching my own dns servers to obtain the actual zone records.
dotcom.txt
dotcomdotau.txt
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
1. I am still not catching what tID means; What is a tID?
2. You mentions that you get a blank array sometimes; when does this occur?
3. When you say matching fields; what data are you matching against?
4. Where is the data coming from?
5. Where is the date going?

Please reference these numbers when answering.
0
 

Author Comment

by:Ciphertel
Comment Utility
1.) tld from memory is Top Level Domain as is a part of the string that makes up a domain name. wikpedia gives more detailed information but here is a link to a good explanation > http://www.chameleonintegration.com/2006/04/28/what-is-a-tld-domain-name/

2.) A blank array will occur if the domain is not registered or purged (nonexistant)

3.) If you look at the attached file domains.txt it contains a sql dump of the table structure of my database and the relevant fields i wish to populate. not all whois servers will return all the fields i require so we need to match what is returned in the raw array with the fields i wish to populate in the database.( I.E. domainName,registrar,expiration date,status,nameserver1,nameserver2,registrant,mx1 record,mx2 record)

4.) The data is returned from a whois query being performed at the beginning of the code routing. the whois query is performed after obtaing one of the domains from the sql database matching my search criteria.

5.) The data is then updated back into the relevant fields in the sql databse
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
Thanks so much for the info!

Two more questions:

1. Basically you want to expand the UPDATE query to SET all fields instead of the few it is doing now, right?

So far it looks like these are matching up well, correct me if I am wrong:

FIELDS to UPDATE, input from:
`domainName`, [regrinfo][domain][name]
`registrar`, [regyinfo][registrar]
`expiration`, [regrinfo][domain][expires]
`status`, [regrinfo][domain][status]
`lastChecked`, NOW()
`nameserver1` [regrinfo][domain][nserver][0]
`nameserver2` [regrinfo][domain][nserver][1]



Unexampled raw information:
2. What would you be searching for for these fields?

`registrant`, [rawdata][*match regex after Registrant Name: *]
`mx1`, [rawdata][*match regex after ???: *]
`mx2`, [rawdata][*match regex after ???: *]
`host`, [rawdata][*match regex after ???: *]

Please post any examples where these information fields are present in record. Or point me to where the data is located; namely: mx1, mx2, and host

Thank you
0
 

Author Comment

by:Ciphertel
Comment Utility
the Registrant is the Owner of the domain and is shown in the sample data provided.

the additional fileds "mx1","mx2","host" are not returned in the array from the whois server.
For this an additional function using a dig command would be needed to query the designated dns server. I do not know how to do this from a code perspective in php at this time. only using command line dig command at the linux command line.

As long as all relevant data is matched to my strings for writing into the database to begin with regardless of the typ of tld thats is a start.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
Sounds good. I'll see what I can do then. I'll most likely post the solution in 24-48 hours.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
Sorry about the delay. See how this works for you.
<?

include ("./phpwhois-4.1.3/whois.main.php");

 

$nameserver1 = "";

$nameserver2 = "";

$registrar = "";

$status = "";

$owner = "";

$registrant = "";

 

 

$username = "root";

$password = "letmein";

$hostname = "10.0.2.13";

 

        

$dbh = mysql_connect($hostname, $username, $password)

        or die("Unable to connect to MySQL");

 

 

mysql_select_db("domains", $dbh);

 

 

 

 

// Select one domain from the database that hasn't been checked yet

$sql = "SELECT domainName from domains ORDER BY lastChecked ASC LIMIT 1";

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$domain_check = $row[0];

 

 

if(mysql_num_rows($result) == 0){

    die("No domains found in the database.");

print "No domains found in the database.";

}

 

 
 
 

 

$whois = new Whois();

$result = $whois->Lookup($domain_check);
 
 
 
 

$lastchecked ='NOW()';

if (isset($result['regrinfo']))

{ 

 if (isset($result['regrinfo']['registered']))

 {

  $status = $result['regrinfo']['registered'];

 }

 if (isset($result['regrinfo']['domain']))

 {

  if (isset($result['regrinfo']['domain']['name']))

  {

   $domainname = $result['regrinfo']['domain']['name'];

  }else{

   $domainname = $domain_check;

  } 

  if (isset($result['regrinfo']['domain']['nserver']))

  {

   $nserver = $result['regrinfo']['domain']['nserver'];

   if (is_array($nserver))

   {

    $nameserver = array_keys($result['regrinfo']['domain']['nserver']);

    $nameserver1 = $nameserver[0];

    $nameserver2 = $nameserver[1];

   }else{

    $nameserver1 = $nserver;

    $nameserver2 = '';

   }

  }

  if (isset($result['regrinfo']['domain']['expires']))

  {

   $expiration = $result['regrinfo']['domain']['expires'];

  }

  if (isset($result['regrinfo']['domain']['status']))

  {

   $status = $result['regrinfo']['domain']['status'];

   if (is_array($status))

   {

    $status = $status[0];

   }

  }

 }

}

if (isset($result['regyinfo']))

{

 if (isset($result['regyinfo']['registrar']))

 {

  $registrar = $result['regyinfo']['registrar'];

 }

}

if (isset($result['rawdata'])){

 foreach ($result['rawdata'] as $key => value){
 

  if(stripos($value, 'Registrant Name:') !== FALSE)

  {

   $registrant = trim(substr($value, 16));

   break;

  }

 }

}
 

 

// domainName, registrar, expiration, status, lastChecked, nameserver1, nameserver2, registrant, mx1, mx2, host

// x, x, x, x, x, x, x, x, x, ?, ?, ?
 

 

print_r ($result);

 

// Update domain information in database

$sql = "UPDATE domains SET 

domainName='" . $domainname . 

"', registrar='" . $registrar . 

"', expiration='" . $expiration . 

"', status='" . $status . 

"', lastChecked=NOW(), nameserver1='" . $nameserver1 . 

"', nameserver2='" . $nameserver2 . 

"', registrant='" . $registrant . 

"';";
 

echo $sql;
 

//mysql_query($sql);

 

        

 

mysql_close($dbh);

?>

Open in new window

0
 

Author Comment

by:Ciphertel
Comment Utility
Currently getting a syntax error at line 98, but cannot see what is the cause of it myself !
PHP Parse error:  syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /root/whois4.php on line 98
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
what is on your line 98?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
I show whitespace line ?
0
 

Author Comment

by:Ciphertel
Comment Utility
foreach ($result['rawdata'] as $key => value){  
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Ciphertel
Comment Utility
Here it is in its current format
<?

include ("./phpwhois-4.1.3/whois.main.php");
 

$nameserver1 = "";

$nameserver2 = "";

$registrar = "";

$status = "";

$owner = "";

$registrant = "";
 
 

$username = "root";

$password = "letmein";

$hostname = "10.0.2.13";
 
 

$dbh = mysql_connect($hostname, $username, $password)

        or die("Unable to connect to MySQL");
 
 

mysql_select_db("domains", $dbh);
 
 
 
 

// Select one domain from the database that hasn't been checked yet

$sql = "SELECT domainName from domains ORDER BY lastChecked ASC LIMIT 1";

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$domain_check = $row[0];
 
 

if(mysql_num_rows($result) == 0){

    die("No domains found in the database.");

print "No domains found in the database.";

}
 
 
 
 
 

$whois = new Whois();

$result = $whois->Lookup($domain_check);
 
 
 
 

$lastchecked ='NOW()';

if (isset($result['regrinfo']))

{

 if (isset($result['regrinfo']['registered']))

 {

  $status = $result['regrinfo']['registered'];

 }

 if (isset($result['regrinfo']['domain']))

 {

  if (isset($result['regrinfo']['domain']['name']))

  {

   $domainname = $result['regrinfo']['domain']['name'];

  }else{

   $domainname = $domain_check;

  }

  if (isset($result['regrinfo']['domain']['nserver']))

  {

   $nserver = $result['regrinfo']['domain']['nserver'];

   if (is_array($nserver))

   {

    $nameserver = array_keys($result['regrinfo']['domain']['nserver']);

    $nameserver1 = $nameserver[0];

    $nameserver2 = $nameserver[1];

   }else{

    $nameserver1 = $nserver;

    $nameserver2 = '';

   }

  }

  if (isset($result['regrinfo']['domain']['expires']))

  {

   $expiration = $result['regrinfo']['domain']['expires'];

  }

  if (isset($result['regrinfo']['domain']['status']))

  {

   $status = $result['regrinfo']['domain']['status'];

   if (is_array($status))

   {

    $status = $status[0];

   }

  }

 }

}

if (isset($result['regyinfo']))

{

 if (isset($result['regyinfo']['registrar']))

 {

  $registrar = $result['regyinfo']['registrar'];

 }

}

if (isset($result['rawdata'])){

 foreach ($result['rawdata'] as $key => value){
 

  if(stripos($value, 'Registrant Name:') !== FALSE)

  {

   $registrant = trim(substr($value, 16));

   break;

  }

 }

}
 
 
 

print_r ($result);
 

// Update domain information in database

$sql = "UPDATE domains SET

domainName='" . $domainname .

"', registrar='" . $registrar .

"', expiration='" . $expiration .

"', status='" . $status .

"', lastChecked=NOW(), nameserver1='" . $nameserver1 .

"', nameserver2='" . $nameserver2 .

"', registrant='" . $registrant .

"';";
 

echo $sql;
 

//mysql_query($sql);
 
 
 

mysql_close($dbh);

?>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
foreach ($result['rawdata'] as $key => $value)
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
Fixed.
<?

include ("./phpwhois-4.1.3/whois.main.php");

 

$nameserver1 = "";

$nameserver2 = "";

$registrar = "";

$status = "";

$owner = "";

$registrant = "";

 

 

$username = "root";

$password = "letmein";

$hostname = "10.0.2.13";

 

 

$dbh = mysql_connect($hostname, $username, $password)

        or die("Unable to connect to MySQL");

 

 

mysql_select_db("domains", $dbh);

 

 

 

 

// Select one domain from the database that hasn't been checked yet

$sql = "SELECT domainName from domains ORDER BY lastChecked ASC LIMIT 1";

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$domain_check = $row[0];

 

 

if(mysql_num_rows($result) == 0){

    die("No domains found in the database.");

print "No domains found in the database.";

}

 

 

 

 

 

$whois = new Whois();

$result = $whois->Lookup($domain_check);

 

 

 

 

$lastchecked ='NOW()';

if (isset($result['regrinfo']))

{

 if (isset($result['regrinfo']['registered']))

 {

  $status = $result['regrinfo']['registered'];

 }

 if (isset($result['regrinfo']['domain']))

 {

  if (isset($result['regrinfo']['domain']['name']))

  {

   $domainname = $result['regrinfo']['domain']['name'];

  }else{

   $domainname = $domain_check;

  }

  if (isset($result['regrinfo']['domain']['nserver']))

  {

   $nserver = $result['regrinfo']['domain']['nserver'];

   if (is_array($nserver))

   {

    $nameserver = array_keys($result['regrinfo']['domain']['nserver']);

    $nameserver1 = $nameserver[0];

    $nameserver2 = $nameserver[1];

   }else{

    $nameserver1 = $nserver;

    $nameserver2 = '';

   }

  }

  if (isset($result['regrinfo']['domain']['expires']))

  {

   $expiration = $result['regrinfo']['domain']['expires'];

  }

  if (isset($result['regrinfo']['domain']['status']))

  {

   $status = $result['regrinfo']['domain']['status'];

   if (is_array($status))

   {

    $status = $status[0];

   }

  }

 }

}

if (isset($result['regyinfo']))

{

 if (isset($result['regyinfo']['registrar']))

 {

  $registrar = $result['regyinfo']['registrar'];

 }

}

if (isset($result['rawdata']))

{

 foreach ($result['rawdata'] as $key => $value)

 { 

  if(stripos($value, 'Registrant Name:') !== FALSE)

  {

   $registrant = trim(substr($value, 16));

   break;

  }

 }

}

 

 

 

print_r ($result);

 

// Update domain information in database

$sql = "UPDATE domains SET

domainName='" . $domainname .

"', registrar='" . $registrar .

"', expiration='" . $expiration .

"', status='" . $status .

"', lastChecked=NOW(), nameserver1='" . $nameserver1 .

"', nameserver2='" . $nameserver2 .

"', registrant='" . $registrant .

"';";

 

echo $sql;

 

//mysql_query($sql);

 

 

 

mysql_close($dbh);

?>

Open in new window

0
 

Author Comment

by:Ciphertel
Comment Utility
lol sorry, just seen your post, was about to tell you missing '$' of string definition.
testing now :)
0
 

Author Comment

by:Ciphertel
Comment Utility
domain 'engravers.biz' returns a registrar of neulevel which is actually the organisation responsible for .biz domains.

and the update query has no criteria for the update, hence updates all records to the output. so far. should have a where domain=$domainname
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
... that would be a problem.

Fixed. Now you have a WHERE clause. :)

Can you output the tld debug I put in this reversion?

Thanks!
<?

include ("./phpwhois-4.1.3/whois.main.php");

 

$nameserver1 = "";

$nameserver2 = "";

$registrar = "";

$status = "";

$owner = "";

$registrant = "";

 

 

$username = "root";

$password = "letmein";

$hostname = "10.0.2.13";

 

 

$dbh = mysql_connect($hostname, $username, $password)

        or die("Unable to connect to MySQL");

 

 

mysql_select_db("domains", $dbh);

 

 

 

 

// Select one domain from the database that hasn't been checked yet

$sql = "SELECT domainName from domains ORDER BY lastChecked ASC LIMIT 1";

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$domain_check = $row[0];

 

 

if(mysql_num_rows($result) == 0){

    die("No domains found in the database.");

print "No domains found in the database.";

}

 

 

 

 

 

$whois = new Whois();

$result = $whois->Lookup($domain_check);

 

$tld = substr($domain_check, (strrchr($domain_check, '.')+1));

echo 'tdl=' . $tld . '<br />';

 

 

$lastchecked ='NOW()';

if (isset($result['regrinfo']))

{

 if (isset($result['regrinfo']['registered']))

 {

  $status = $result['regrinfo']['registered'];

 }

 if (isset($result['regrinfo']['domain']))

 {

  if (isset($result['regrinfo']['domain']['name']))

  {

   $domainname = $result['regrinfo']['domain']['name'];

  }else{

   $domainname = $domain_check;

  }

  if (isset($result['regrinfo']['domain']['nserver']))

  {

   $nserver = $result['regrinfo']['domain']['nserver'];

   if (is_array($nserver))

   {

    $nameserver = array_keys($result['regrinfo']['domain']['nserver']);

    $nameserver1 = $nameserver[0];

    $nameserver2 = $nameserver[1];

   }else{

    $nameserver1 = $nserver;

    $nameserver2 = '';

   }

  }

  if (isset($result['regrinfo']['domain']['expires']))

  {

   $expiration = $result['regrinfo']['domain']['expires'];

  }

  if (isset($result['regrinfo']['domain']['status']))

  {

   $status = $result['regrinfo']['domain']['status'];

   if (is_array($status))

   {

    $status = $status[0];

   }

  }

 }

}

if (isset($result['regyinfo']))

{

 if (isset($result['regyinfo']['registrar']))

 {

  $registrar = $result['regyinfo']['registrar'];

 }

}

if (isset($result['rawdata']))

{

 foreach ($result['rawdata'] as $key => $value)

 { 

  if(stripos($value, 'Registrant Name:') !== FALSE)

  {

   $registrant = trim(substr($value, 16));

   break;

  }

 }

}

 

 

 

print_r ($result);

 

// Update domain information in database

$sql = "UPDATE domains SET

domainName='" . $domainname .

"', registrar='" . $registrar .

"', expiration='" . $expiration .

"', status='" . $status .

"', lastChecked=NOW(), nameserver1='" . $nameserver1 .

"', nameserver2='" . $nameserver2 .

"', registrant='" . $registrant .

"' WHERE domainName = '" . $domainname . "';";

 

echo $sql;

 

//mysql_query($sql);

 

 

 

mysql_close($dbh);

?>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
as far as the TLD casing I need to see if my substr for the tld worked properly.
 Basically if there are minor variations between the TLD we could if statement it out inside after if (isset( passes
0
 

Author Comment

by:Ciphertel
Comment Utility
Sorry was away for my first anniversary. back onboard now.

Here is the output for a .com.au domain.

The tld string that you are echoing to the screen is truncated
the registrar information is incorrect and the registrant is not being parsed back.
results.txt
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
how much was it truncated? off by 1 char?
0
 

Author Comment

by:Ciphertel
Comment Utility
yes, see the attached file
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
Thanks.

tld should now output:

au

<?

include ("./phpwhois-4.1.3/whois.main.php");

 

$nameserver1 = "";

$nameserver2 = "";

$registrar = "";

$status = "";

$owner = "";

$registrant = "";

 

 

$username = "root";

$password = "letmein";

$hostname = "10.0.2.13";

 

 

$dbh = mysql_connect($hostname, $username, $password)

        or die("Unable to connect to MySQL");

 

 

mysql_select_db("domains", $dbh);

 

 

 

 

// Select one domain from the database that hasn't been checked yet

$sql = "SELECT domainName from domains ORDER BY lastChecked ASC LIMIT 1";

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$domain_check = $row[0];

 

 

if(mysql_num_rows($result) == 0){

    die("No domains found in the database.");

print "No domains found in the database.";

}

 

 

 

 

 

$whois = new Whois();

$result = $whois->Lookup($domain_check);

 

$tld = substr(strrchr($domain_check, '.'), 1);

echo 'tdl=' . $tld . '<br />';

 

 

$lastchecked ='NOW()';

if (isset($result['regrinfo']))

{

 if (isset($result['regrinfo']['registered']))

 {

  $status = $result['regrinfo']['registered'];

 }

 if (isset($result['regrinfo']['domain']))

 {

  if (isset($result['regrinfo']['domain']['name']))

  {

   $domainname = $result['regrinfo']['domain']['name'];

  }else{

   $domainname = $domain_check;

  }

  if (isset($result['regrinfo']['domain']['nserver']))

  {

   $nserver = $result['regrinfo']['domain']['nserver'];

   if (is_array($nserver))

   {

    $nameserver = array_keys($result['regrinfo']['domain']['nserver']);

    $nameserver1 = $nameserver[0];

    $nameserver2 = $nameserver[1];

   }else{

    $nameserver1 = $nserver;

    $nameserver2 = '';

   }

  }

  if (isset($result['regrinfo']['domain']['expires']))

  {

   $expiration = $result['regrinfo']['domain']['expires'];

  }

  if (isset($result['regrinfo']['domain']['status']))

  {

   $status = $result['regrinfo']['domain']['status'];

   if (is_array($status))

   {

    $status = $status[0];

   }

  }

 }

}

if (isset($result['regyinfo']))

{

 if (isset($result['regyinfo']['registrar']))

 {

  $registrar = $result['regyinfo']['registrar'];

 }

}

if (isset($result['rawdata']))

{

 foreach ($result['rawdata'] as $key => $value)

 { 

  if(stripos($value, 'Registrant Name:') !== FALSE)

  {

   $registrant = trim(substr($value, 16));

   break;

  }

 }

}

 

 

 

print_r ($result);

 

// Update domain information in database

$sql = "UPDATE domains SET

domainName='" . $domainname .

"', registrar='" . $registrar .

"', expiration='" . $expiration .

"', status='" . $status .

"', lastChecked=NOW(), nameserver1='" . $nameserver1 .

"', nameserver2='" . $nameserver2 .

"', registrant='" . $registrant .

"' WHERE domainName = '" . $domainname . "';";

 

echo $sql;

 

//mysql_query($sql);

 

 

 

mysql_close($dbh);

?>

Open in new window

0
 

Author Comment

by:Ciphertel
Comment Utility
Yes it does.

registrar = AU-NIC
and registrant value null

for au prob easier to just branch for different tlds. In xase of au use raw data for registrant and registrar name.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
That is exact why I needed the tld to work first.

Now that it works we can SWITCH (select case) the tlds for their different data patterns.

Do me a favor and upload the whois data from domains with ending prefix:
.com .au .org .*whatever else you need to parse.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
suffix i mean
0
 

Author Comment

by:Ciphertel
Comment Utility
Ok i have attached a heap of the results.
One thing I will clarify, If the domain is registered then regardless of the registrar result for status i would like it to say 'ok'

If it returns no for registered then that will become the status. Thanks
results.txt
0
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 500 total points
Comment Utility
Status to "ok"
<?

include ("./phpwhois-4.1.3/whois.main.php");

 

$nameserver1 = "";

$nameserver2 = "";

$registrar = "";

$status = "";

$owner = "";

$registrant = "";

 

 

$username = "root";

$password = "letmein";

$hostname = "10.0.2.13";

 

 

$dbh = mysql_connect($hostname, $username, $password)

        or die("Unable to connect to MySQL");

 

 

mysql_select_db("domains", $dbh);

 

 

 

 

// Select one domain from the database that hasn't been checked yet

$sql = "SELECT domainName from domains ORDER BY lastChecked ASC LIMIT 1";

$result = mysql_query($sql);

$row = mysql_fetch_row($result);

$domain_check = $row[0];

 

 

if(mysql_num_rows($result) == 0){

    die("No domains found in the database.");

print "No domains found in the database.";

}

 

 

 

 

 

$whois = new Whois();

$result = $whois->Lookup($domain_check);

 

$tld = substr(strrchr($domain_check, '.'), 1);

echo 'tdl=' . $tld . '<br />';

 

 

$lastchecked ='NOW()';

if (isset($result['regrinfo']))

{

 if (isset($result['regrinfo']['registered']))

 {

  $status = $result['regrinfo']['registered'];

 }

 if (isset($result['regrinfo']['domain']))

 {

  if (isset($result['regrinfo']['domain']['name']))

  {

   $domainname = $result['regrinfo']['domain']['name'];

  }else{

   $domainname = $domain_check;

  }

  if (isset($result['regrinfo']['domain']['nserver']))

  {

   $nserver = $result['regrinfo']['domain']['nserver'];

   if (is_array($nserver))

   {

    $nameserver = array_keys($result['regrinfo']['domain']['nserver']);

    $nameserver1 = $nameserver[0];

    $nameserver2 = $nameserver[1];

   }else{

    $nameserver1 = $nserver;

    $nameserver2 = '';

   }

  }

  if (isset($result['regrinfo']['domain']['expires']))

  {

   $expiration = $result['regrinfo']['domain']['expires'];

  }

  if (isset($result['regrinfo']['domain']['status']))

  {

   $status = $result['regrinfo']['domain']['status'];

   if (is_array($status))

   {

    if ($status != "expired"){

     $status = "ok";

    }

   }

  }

 }

}

if (isset($result['regyinfo']))

{

 if (isset($result['regyinfo']['registrar']))

 {

  $registrar = $result['regyinfo']['registrar'];

 }

}

if (isset($result['rawdata']))

{

 foreach ($result['rawdata'] as $key => $value)

 { 

  if(stripos($value, 'Registrant Name:') !== FALSE)

  {

   $registrant = trim(substr($value, 16));

   break;

  }

 }

}

 

 

 

print_r ($result);

 

// Update domain information in database

$sql = "UPDATE domains SET

domainName='" . $domainname .

"', registrar='" . $registrar .

"', expiration='" . $expiration .

"', status='" . $status .

"', lastChecked=NOW(), nameserver1='" . $nameserver1 .

"', nameserver2='" . $nameserver2 .

"', registrant='" . $registrant .

"' WHERE domainName = '" . $domainname . "';";

 

echo $sql;

 

//mysql_query($sql);

 

 

 

mysql_close($dbh);

?>

Open in new window

0
 

Author Closing Comment

by:Ciphertel
Comment Utility
Whilst the information returned is what was required (except for registry) different registrars return the information in different formats. looks like the true test will be to strip out the data required from the raw data array.

This was definatly not an easy task and kudos for nerds of tech for assisting. his answers made it easier to understand why i wasn't gettinig consistant information.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now