Php whois API extract raw data fields from array

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
CiphertelAsked:
Who is Participating?
 
NerdsOfTechTechnology ScientistCommented:
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
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
CiphertelAuthor Commented:
Additional points awarded for completion of script
0
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
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
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
Sounds good. I'll see what I can do then. I'll most likely post the solution in 24-48 hours.
0
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
what is on your line 98?
0
 
NerdsOfTechTechnology ScientistCommented:
I show whitespace line ?
0
 
CiphertelAuthor Commented:
foreach ($result['rawdata'] as $key => value){  
0
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
foreach ($result['rawdata'] as $key => $value)
0
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
lol sorry, just seen your post, was about to tell you missing '$' of string definition.
testing now :)
0
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
... 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
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
how much was it truncated? off by 1 char?
0
 
CiphertelAuthor Commented:
yes, see the attached file
0
 
NerdsOfTechTechnology ScientistCommented:
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
 
CiphertelAuthor Commented:
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
 
NerdsOfTechTechnology ScientistCommented:
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
 
NerdsOfTechTechnology ScientistCommented:
suffix i mean
0
 
CiphertelAuthor Commented:
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
 
CiphertelAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.