?
Solved

PHP Whois Script au Problem

Posted on 2009-04-22
2
Medium Priority
?
734 Views
Last Modified: 2013-12-13
Hi,

I obtained a whois script to check from domain availability from here: www.soaptray.com

The script works perfectly well, except for .au domains. They always give me the result as "Not Available"

I have tried changing the server settings but to no effect. Does anyone have any ideas on how to fix this?


<?PHP
	//----------------------------------------------------------------
	// 	PHP FORM
	//----------------------------------------------------------------	
 
		if (empty($user_domain)){
			$domain_error = "Domain Name Cannot Be empty";
		} else {
		
			if (eregi('^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$',$user_domain) != 1){			
				$domain_error = 'Invalid domain (Letters, numbers and hyphens only): "'.$user_domain.'"';			
			} else {		
		
				//no errors, perform search
	
				//$domain = 'enterit';
				
				$whois = new whois;
				$result = $whois->available($user_domain);
			
			}
		
		}
?>
 
<?PHP
 
	//----------------------------------------------------------------
	// 	WHOIS LOOKUP CLASS
	//----------------------------------------------------------------	
	
	class whois {
	
		public $ext = array(
			'.com.au' => array('whois.ausregistry.com.au','No data Found'),
			'.net.au' => array('whois.ausregistry.com.au','No data Found'),
			'.com' => array('whois.crsnic.net','No match for'),
			'.net' => array('whois.crsnic.net','No match for'),	  
			'.org' => array('whois.publicinterestregistry.net','NOT FOUND'),	
			
			'.biz' => array('whois.biz','Not found'),
			'.info' => array('whois.afilias.net','NOT FOUND'),	
			'.mobi' => array('whois.dotmobiregistry.net', 'NOT FOUND'),
			'.tel' => array('whois.nic.tel','No match'),
			'.tv' => array('whois.nic.tv', 'No match for'),
			'.in' => array('whois.inregistry.net', 'NOT FOUND'),
			'.us' => array('whois.nic.us','Not Found'),
			'.name' => array('whois.nic.name','No match'),
			);
		
		public $error;
 
		function available($domain){
		
			$avail_domains = $taken_domains = "";
		
		
			$domain = trim($domain);
			
			//check for extention (probably want to remove this)
			preg_match('@^(http://www\.|http://|www\.)?([^/]+)@i', $domain, $preg_metch_result);
			$f_result = '';
			$domain = $preg_metch_result[2];
			$domain_name_array = explode('.', $domain);
			$domain_domain = strtolower(trim($domain_name_array[count($domain_name_array)-1]));
			
			$ext_in_list = false;			
			if (array_key_exists('.'.$domain_domain, $this->ext)){
				$ext_in_list = true;
			}
			
			if(strlen($domain) > 0){		
				//echo count($this->ext) . " item in array<br /><br />";
				
				foreach ($this->ext as $key => $value){
	
					$server = '';
					$server = $this->ext[$key][0];	
					
					echo $domain.$key;
					
					$lookup_result = gethostbyname($server);
					
					/*
					if ($lookup_result == $server){
						$error = 'Error: Invalid extension - '.$key.'. / server has outgoing connections blocked to '.$server.'.';
						//return false;
						
						echo "<span style='color:#FF0000'>$error</span><br />";
					}*/		
					
					$fs = fsockopen($server, 43,$errno,$errstr,10);		
					
					/*
					if (!$fs || ($errstr != "")){
						$error = 'Error: ('.$server.') '.$errstr.' ('.$errno.')';
						//return false;
						echo "<span style='color:#FF0000'>$error</span><br />";
					}*/
					
					fputs($fs, "$domain\r\n");
					while( !feof($fs) ) {
						$f_result .= fgets($fs,128);
					}
					
					fclose($fs);				
						
					if($domain_domain == 'org'){
						nl2br($f_result);
					}
					
					if(eregi($this->ext[$key][1], $f_result)){
						//return true;
						
						echo "<span style='color:#00FF00'>AVAILABLE</span><br />";
						
					} else {
						//return false;
						
						echo "<span style='color:#FF0000'>NOT AVAILABLE</span><br />";
					}
								
				}
			}
		}
	}
?>

Open in new window

0
Comment
Question by:jset_expert
2 Comments
 
LVL 1

Author Comment

by:jset_expert
ID: 24210782
Hi, the problem here is not the .au extention.

I actually have the same problem for ALL 2nd level domain names. e.g. .co.uk also does not work.

Should I be connecting to the whois server differently?

Any help is much appreciated
0
 
LVL 6

Accepted Solution

by:
basic612 earned 2000 total points
ID: 24214852
Your script works fine for me, except in testing it out I soon blacklisted my IP address for excessive lookups:

Debug $f_result

BLACKLISTED: You have exceeded the query limit for your network or IP address and have been blacklisted.

Could this be the problem you are seeing? My test code (which produced valid lookups for a short while) is below:
<?PHP
        //----------------------------------------------------------------
        //      PHP FORM
        //----------------------------------------------------------------      
 
$user_domain = 'lookthisup';
                if (empty($user_domain)){
                        $domain_error = "Domain Name Cannot Be empty";
                } else {
                
                        if (eregi('^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$',$user_domain) != 1){                        
                                $domain_error = 'Invalid domain (Letters, numbers and hyphens only): "'.$user_domain.'"';                       
                        } else {                
                
                                //no errors, perform search
        
                                //$domain = 'enterit';
                                
                                $whois = new whois;
                                $result = $whois->available($user_domain);
                        
                        }
                
                }
?>
 
<?PHP
 
        //----------------------------------------------------------------
        //      WHOIS LOOKUP CLASS
        //----------------------------------------------------------------      
        
        class whois {
        
                public $ext = array(
                        '.com.au' => array('whois.ausregistry.com.au','No data Found'),
                        '.net.au' => array('whois.ausregistry.com.au','No data Found'),
                        '.com' => array('whois.crsnic.net','No match for'),
                        '.net' => array('whois.crsnic.net','No match for'),       
                        '.org' => array('whois.publicinterestregistry.net','NOT FOUND'),        
                        
                        '.biz' => array('whois.biz','Not found'),
                        '.info' => array('whois.afilias.net','NOT FOUND'),      
                        '.mobi' => array('whois.dotmobiregistry.net', 'NOT FOUND'),
                        '.tel' => array('whois.nic.tel','No match'),
                        '.tv' => array('whois.nic.tv', 'No match for'),
                        '.in' => array('whois.inregistry.net', 'NOT FOUND'),
                        '.us' => array('whois.nic.us','Not Found'),
                        '.name' => array('whois.nic.name','No match'),
                        );
                
                public $error;
 
                function available($domain){
                
                        $avail_domains = $taken_domains = "";
                
                
                        $domain = trim($domain);
                        
                        //check for extention (probably want to remove this)
                        preg_match('@^(http://www\.|http://|www\.)?([^/]+)@i', $domain, $preg_metch_result);
                        $f_result = '';
                        $domain = $preg_metch_result[2];
                        $domain_name_array = explode('.', $domain);
                        $domain_domain = strtolower(trim($domain_name_array[count($domain_name_array)-1]));
                        
                        $ext_in_list = false;                   
                        if (array_key_exists('.'.$domain_domain, $this->ext)){
                                $ext_in_list = true;
                        }
                        
                        if(strlen($domain) > 0){                
                                //echo count($this->ext) . " item in array<br /><br />";
                                
                                foreach ($this->ext as $key => $value){
        
                                        $server = '';
                                        $server = $this->ext[$key][0];  
                                        
                                        echo $domain.$key;
                                        
                                        $lookup_result = gethostbyname($server);
                                        
                                        /*
                                        if ($lookup_result == $server){
                                                $error = 'Error: Invalid extension - '.$key.'. / server has outgoing connections blocked to '.$server.'.';
                                                //return false;
                                                
                                                echo "<span style='color:#FF0000'>$error</span><br />";
                                        }*/             
                                        
                                        $fs = fsockopen($server, 43,$errno,$errstr,10);         
                                        
                                        /*
                                        if (!$fs || ($errstr != "")){
                                                $error = 'Error: ('.$server.') '.$errstr.' ('.$errno.')';
                                                //return false;
                                                echo "<span style='color:#FF0000'>$error</span><br />";
                                        }*/
                                        
                                        fputs($fs, "$domain\r\n");
                                        while( !feof($fs) ) {
                                                $f_result .= fgets($fs,128);
                                        }
                                        
                                        fclose($fs);                            
                                                
                                        if($domain_domain == 'org'){
                                                nl2br($f_result);
                                        }
                                        
                                        if(eregi($this->ext[$key][1], $f_result)){
                                                //return true;
                                        	
                                                echo "<span style='color:#00FF00'>AVAILABLE</span><br />";
                                                
                                        } else {
                                                //return false;
                                                // Debug $f_result
                                                echo '<hr noshade /><strong>Debug $f_result</strong><pre>'.print_r($f_result,true)."</pre><hr noshade />\n";
                                                
                                                
                                                echo "<span style='color:#FF0000'>NOT AVAILABLE</span><br />";
                                        }
                                                                
                                }
                        }
                }
        }
?>

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses
Course of the Month15 days, 18 hours left to enroll

850 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