Solved

Php whois API extract raw data fields from array

Posted on 2009-05-05
34
1,416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 16
34 Comments
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24310427
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
ID: 24310646
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
ID: 24310653
Additional points awarded for completion of script
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24313188
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
ID: 24313382
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
ID: 24313440
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
ID: 24313501
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
ID: 24313653
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
ID: 24314008
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
ID: 24314352
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
ID: 24317654
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
ID: 24352927
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
ID: 24353163
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
ID: 24353236
what is on your line 98?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24353238
I show whitespace line ?
0
 

Author Comment

by:Ciphertel
ID: 24353278
foreach ($result['rawdata'] as $key => value){  
0
 

Author Comment

by:Ciphertel
ID: 24353293
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
ID: 24353299
foreach ($result['rawdata'] as $key => $value)
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24353302
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
ID: 24353484
lol sorry, just seen your post, was about to tell you missing '$' of string definition.
testing now :)
0
 

Author Comment

by:Ciphertel
ID: 24353561
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
ID: 24358723
... 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
ID: 24358817
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
ID: 24364026
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
ID: 24367683
how much was it truncated? off by 1 char?
0
 

Author Comment

by:Ciphertel
ID: 24370453
yes, see the attached file
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24377924
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
ID: 24380638
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
ID: 24380783
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
ID: 24380786
suffix i mean
0
 

Author Comment

by:Ciphertel
ID: 24394857
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
ID: 24564278
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
ID: 31577957
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

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

636 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