whois

  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

Quick question. I have the following code and one line is bugging me. Here's the complete code:

Code: [ Select ]
function whois ($a_server, $a_query, $a_port=43) {
    $available = "No match";
    $a_query = str_replace("www.", "", $a_query);
    $a_query = str_replace("http://", "", $a_query);
    
    //connects to whois to search for username
    $sock = fsockopen($a_server,$a_port);
    if(!$sock) {
        echo 'Could Not Connect To Server.';
    }
    
    //write the query to whois
    fputs($sock,"$a_query\r\n");
    //get the line of results
    while(!feof($sock)) $result .= fgets($sock,128);
    //close the connection

    fclose($sock);
    
    if (eregi($available,$result)) {
        echo $a_query . ' is available.';
    } else {
        echo $a_query . ' is not available.</b></font>';
    }

}

if($query != ''){
    if(!eregi(".com",$query) AND !eregi(".net",$query) AND !eregi(".org",$query)) {
        echo 'You must specify a .com, .net, or .org domain name.';
    } else {
        $server = 'whois.internic.net';
        whois($server,$query);
    }
} elseif(isset($query)) {
    echo 'Please fill in a domain name and try again.';
}
  1. function whois ($a_server, $a_query, $a_port=43) {
  2.     $available = "No match";
  3.     $a_query = str_replace("www.", "", $a_query);
  4.     $a_query = str_replace("http://", "", $a_query);
  5.     
  6.     //connects to whois to search for username
  7.     $sock = fsockopen($a_server,$a_port);
  8.     if(!$sock) {
  9.         echo 'Could Not Connect To Server.';
  10.     }
  11.     
  12.     //write the query to whois
  13.     fputs($sock,"$a_query\r\n");
  14.     //get the line of results
  15.     while(!feof($sock)) $result .= fgets($sock,128);
  16.     //close the connection
  17.     fclose($sock);
  18.     
  19.     if (eregi($available,$result)) {
  20.         echo $a_query . ' is available.';
  21.     } else {
  22.         echo $a_query . ' is not available.</b></font>';
  23.     }
  24. }
  25. if($query != ''){
  26.     if(!eregi(".com",$query) AND !eregi(".net",$query) AND !eregi(".org",$query)) {
  27.         echo 'You must specify a .com, .net, or .org domain name.';
  28.     } else {
  29.         $server = 'whois.internic.net';
  30.         whois($server,$query);
  31.     }
  32. } elseif(isset($query)) {
  33.     echo 'Please fill in a domain name and try again.';
  34. }


What the heck does this part do?

Code: [ Select ]
while(!feof($sock)) $result .= fgets($sock,128);


Is it writing line 128 to variable result? Because if it is, I don't understand how this shows that a domain is available since there's nothing on whois.internic.net that I can see with my eye. I downloaded this from a hotscripts type website (i broke my #1 rule!) to try and figure out whe the author has done, but I don't get it. Well, I think I get it, but I'm not sure how the heck he's getting his results.

Advice?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

Sorry. Also, the comments are my own. My way of "learning" from somebody else's code.
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

Actually, exec(whois domain.suffix) works great. Problem solved! Mod, feel free to delete this whole thread if you want since it appears I'm just talking to myself anyway.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

gsv2com wrote:
What the heck does this part do?

Code: [ Select ]
while(!feof($sock)) $result .= fgets($sock,128);




That line is reading the file descriptor $sock as long as it doesn't reach the end of the content. Each string (up to 128 bytes) is being appended to $result.
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

The above code is a cheap hack at solving the problem. I found an easier, more accurate way.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Great, post the solution here, so others can take advantage too.
  • gsv2com
  • Professor
  • Professor
  • User avatar
  • Posts: 776
  • Loc: Nippon

Post 3+ Months Ago

I'll do so as soon as I have the code perfected. :)

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 55 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.