Hi, I really don't know if it's the proper place to ask this, but I don't know anywhere else!
Anyways, as you can see in my location I'm living in Iran and it's just one company ( www.nic.com) who gives .ir ccTLD, if you go to the site you see that they have a place to search for all the .ir domains and their info ( whois), when I asked them to give me the open port that I can connect by PHP and look up my domain name, they said that they do not open their port for this.
What I'm asking is : is it legal that they just keep their whois for themselves? I just wana use it in my site that ppl who wana buy domains can look up the name and see if it exists, a real normal use of it! And if it's illegal, where can I report it? Any international community or something?
They even didn't give me a reason for this!

Thanx in advance

    Which port do you mean? You don't need a special port to execute a whois request.

    <?php
        if (!isset($addr)) {
            $addr = "php.net";
        }
        $url= "http://www.nic.com/cgi-bin/whois.cgi?query=$addr";
        $fp = @fopen($url,"r");
        if(!$fp) {
            die(print "Warning: Connect Error ($url)<br>");
        }
        while(!feof($fp)) {
            $str = fgets($fp,4096);
    		print $str; // Instead this print you can filter the result
        }
        @fclose($fp);
    ?>
    

      My preferred whois proxy is the one at Geektools, at least for manual lookups. Trying (off the top of my head) president.ir, I get a full record on the nameholder from the whois.nic.ir nameserver.

      It wouldn't be much point in maintaining NICs to keep a registry of domain names if they didn't give out information on whether a domain name was registered or not or who holds it or where to find nameservers - that is the precise reason they exist!

        Dear hand, I tried your script and it didn't work. I didn't know that we can do it with fopen too, I always tried fsockopen.

        Anyways, but you Weedpacket, thanx! Your site definitely works! and about that president.ir it's the ugliest site availabe! Anyways, it's kinda shameful, but what I need is to do that in my own site, so, I need to have the open port that geektools uses. Do you have it or shall I ask them?
        And do you mean that it's always an open port that NIC doesn't want to show and I have to look it up myself? I mean how geektools could do it if NIC didn't give them the open port?

          I don't know why, but I just tested the script and it works.
          Pleas try again, I customized it a little bit

          <?php
              if (!isset($addr)) {
                  $addr = "president.ir";
              }
              // $url= "http://www.nic.com/cgi-bin/whois.cgi?query=$addr";
          	$url= "http://aria.nic.ir/cgi-bin/whois.pl?name=$addr";
              $fp = @fopen($url,"r");
              if(!$fp) {
                  die(print "Warning: Connect Error ($url)<br>");
              }
              while(!feof($fp)) {
                  $str = fgets($fp,4096);
          		if (strpos($str,": ")) {
                     print $str;
          		}
              }
              @fclose($fp);
          ?>
          

            I thought the code looked interesting so dumped it to here:

            http://www.phphacks.com/whois.php

            Works fine... Obviously you could reformat the output so it was better integrated with the look and feel of your site - but looks good to me...

              Hi, thanx to you all! it's cool! it works fine and thank you hand, Also thanx to you Angus, I didn't have to upload it anymore!
              A question now: Is there any special rule that I have to know for checking my domain under any whois server? For example you used http://aria.nic.ir/cgi-bin/whois.pl?name=$addr to pick up the info about president.ir. And surely they don't know that you're doing this coz I contacted the webmaster and he wasn't willing to gimme the open port. So, if I try the following formula can I be sure that I can get all the info about any domain that I want under any whois server?

              Formula: http://aria.MyWhoisServer.ir/cgi-bin/whois.pl?name=TheDomainThatIWanaLookUp

                If NIC.COM don't want to give it out, my guess is that it's number 43 - at least, that's the conventional port for WHOIS queries.

                The advantage of going via geektools is that their whois proxy scouts around for a suitable nameserver based on the top-level domain (instead of relying on nic.com or nic.ir); the disadvantages are that it expects the query in a POST, and you need to parse the response.

                But instead of making you rely on their whois server, Geektool have made its source available. I've just downloaded it, and I'm thinking of porting it from Perl to PHP.

                  Try this

                  <?
                  function get_whois_server($domain){
                  $whoisservers=array(
                  array("ac","whois.nic.ac"),
                  array("ac.cn","whois.cnnic.net.cn"),
                  array("ac.jp","whois.nic.ad.jp"),
                  array("ac.uk","whois.ja.net"),
                  array("ad.jp","whois.nic.ad.jp"),
                  array("adm.br","whois.nic.br"),
                  array("adv.br","whois.nic.br"),
                  array("aero","whois.information.aero"),
                  array("ag","whois.nic.ag"),
                  array("agr.br","whois.nic.br"),
                  array("ah.cn","whois.cnnic.net.cn"),
                  array("al","whois.ripe.net"),
                  array("am.br","whois.nic.br"),
                  array("arq.br","whois.nic.br"),
                  array("at","whois.nic.at"),
                  array("au","whois.aunic.net"),
                  array("art.br","whois.nic.br"),
                  array("as","whois.nic.as"),
                  array("asn.au","whois.aunic.net"),
                  array("ato.br","whois.nic.br"),
                  array("be","whois.geektools.com"),
                  array("bg","whois.digsys.bg"),
                  array("bio.br","whois.nic.br"),
                  array("biz","whois.biz"),
                  array("bj.cn","whois.cnnic.net.cn"),
                  array("bmd.br","whois.nic.br"),
                  array("br","whois.registro.br"),
                  array("ca","whois.cira.ca"),
                  array("cc","whois.nic.cc"),
                  array("cd","whois.cd"),
                  array("ch","whois.nic.ch"),
                  array("cim.br","whois.nic.br"),
                  array("ck","whois.ck-nic.org.ck"),
                  array("cl","whois.nic.cl"),
                  array("cn","whois.cnnic.net.cn"),
                  array("cng.br","whois.nic.br"),
                  array("cnt.br","whois.nic.br"),
                  array("com","rs.internic.net"),
                  array("com.au","whois.aunic.net"),
                  array("com.br","whois.nic.br"),
                  array("com.cn","whois.cnnic.net.cn"),
                  array("com.eg","whois.ripe.net"),
                  array("com.hk","whois.hknic.net.hk"),
                  array("com.mx","whois.nic.mx"),
                  array("com.ru","whois.ripn.ru"),
                  array("com.tw","whois.twnic.net"),
                  array("conf.au","whois.aunic.net"),
                  array("co.jp","whois.nic.ad.jp"),
                  array("co.uk","whois.nic.uk"),
                  array("cq.cn","whois.cnnic.net.cn"),
                  array("csiro.au","whois.aunic.net"),
                  array("cx","whois.nic.cx"),
                  array("cz","whois.nic.cz"),
                  array("de","whois.denic.de"),
                  array("dk","whois.dk-hostmaster.dk"),
                  array("ecn.br","whois.nic.br"),
                  array("ee","whois.eenet.ee"),
                  array("edu","rs.internic.net"),
                  array("edu.au","whois.aunic.net"),
                  array("edu.br","whois.nic.br"),
                  array("eg","whois.ripe.net"),
                  array("es","whois.ripe.net"),
                  array("esp.br","whois.nic.br"),
                  array("etc.br","whois.nic.br"),
                  array("eti.br","whois.nic.br"),
                  array("eun.eg","whois.ripe.net"),
                  array("emu.id.au","whois.aunic.net"),
                  array("eng.br","whois.nic.br"),
                  array("far.br","whois.nic.br"),
                  array("fi","whois.ripe.net"),
                  array("fj","whois.usp.ac.fj"),
                  array("fj.cn","whois.cnnic.net.cn"),
                  array("fm.br","whois.nic.br"),
                  array("fnd.br","whois.nic.br"),
                  array("fo","whois.ripe.net"),
                  array("fot.br","whois.nic.br"),
                  array("fst.br","whois.nic.br"),
                  array("fr","whois.nic.fr"),
                  array("g12.br","whois.nic.br"),
                  array("gd.cn","whois.cnnic.net.cn"),
                  array("ge","whois.ripe.net"),
                  array("ggf.br","whois.nic.br"),
                  array("gl","whois.ripe.net"),
                  array("gr","whois.ripe.net"),
                  array("gr.jp","whois.nic.ad.jp"),
                  array("gs","whois.adamsnames.tc"),
                  array("gov","whois.nic.gov"),
                  array("gs.cn","whois.cnnic.net.cn"),
                  array("gov.au","whois.aunic.net"),
                  array("gov.br","whois.nic.br"),
                  array("gov.cn","whois.cnnic.net.cn"),
                  array("gov.hk","whois.hknic.net.hk"),
                  array("gob.mx","whois.nic.mx"),
                  array("gs","whois.adamsnames.tc"),
                  array("gz.cn","whois.cnnic.net.cn"),
                  array("gx.cn","whois.cnnic.net.cn"),
                  array("he.cn","whois.cnnic.net.cn"),
                  array("ha.cn","whois.cnnic.net.cn"),
                  array("hb.cn","whois.cnnic.net.cn"),
                  array("hi.cn","whois.cnnic.net.cn"),
                  array("hl.cn","whois.cnnic.net.cn"),
                  array("hn.cn","whois.cnnic.net.cn"),
                  array("hm","whois.registry.hm"),
                  array("hk","whois.hknic.net.hk"),
                  array("hk.cn","whois.cnnic.net.cn"),
                  array("hu","whois.ripe.net"),
                  array("id.au","whois.aunic.net"),
                  array("ie","whois.domainregistry.ie"),
                  array("ind.br","whois.nic.br"),
                  array("imb.br","whois.nic.br"),
                  array("inf.br","whois.nic.br"),
                  array("info","whois.afilias.info"),
                  array("info.au","whois.aunic.net"),
                  array("it","whois.nic.it"),
                  array("idv.tw","whois.twnic.net"),
                  array("int","whois.iana.org"),
                  array("is","whois.isnic.is"),
                  array("il","whois.isoc.org.il"),
                  array("jl.cn","whois.cnnic.net.cn"),
                  array("jor.br","whois.nic.br"),
                  array("jp","whois.nic.ad.jp"),
                  array("js.cn","whois.cnnic.net.cn"),
                  array("jx.cn","whois.cnnic.net.cn"),
                  array("kr","whois.krnic.net"),
                  array("la","whois.nic.la"),
                  array("lel.br","whois.nic.br"),
                  array("li","whois.nic.ch"),
                  array("lk","whois.nic.lk"),
                  array("ln.cn","whois.cnnic.net.cn"),
                  array("lt","ns.litnet.lt"),
                  array("lu","whois.dns.lu"),
                  array("lv","whois.ripe.net"),
                  array("ltd.uk","whois.nic.uk"),
                  array("mat.br","whois.nic.br"),
                  array("mc","whois.ripe.net"),
                  array("med.br","whois.nic.br"),
                  array("mil","whois.nic.mil"),
                  array("mil.br","whois.nic.br"),
                  array("mn","whois.nic.mn"),
                  array("mo.cn","whois.cnnic.net.cn"),
                  array("ms","whois.adamsnames.tc"),
                  array("mus.br","whois.nic.br"),
                  array("mx","whois.nic.mx"),
                  array("name","whois.nic.name"),
                  array("ne.jp","whois.nic.ad.jp"),
                  array("net","rs.internic.net"),
                  array("net.au","whois.aunic.net"),
                  array("net.br","whois.nic.br"),
                  array("net.cn","whois.cnnic.net.cn"),
                  array("net.eg","whois.ripe.net"),
                  array("net.hk","whois.hknic.net.hk"),
                  array("net.lu","whois.dns.lu"),
                  array("net.mx","whois.nic.mx"),
                  array("net.uk","whois.nic.uk"),
                  array("net.ru","whois.ripn.ru"),
                  array("net.tw","whois.twnic.net"),
                  array("nl","whois.domain-registry.nl"),
                  array("nm.cn","whois.cnnic.net.cn"),
                  array("no","whois.norid.no"),
                  array("nom.br","whois.nic.br"),
                  array("not.br","whois.nic.br"),
                  array("ntr.br","whois.nic.br"),
                  array("nx.cn","whois.cnnic.net.cn"),
                  array("nz","whois.domainz.net.nz"),
                  array("plc.uk","whois.nic.uk"),
                  array("odo.br","whois.nic.br"),
                  array("oop.br","whois.nic.br"),
                  array("or.jp","whois.nic.ad.jp"),
                  array("org","rs.internic.net"),
                  array("org.au","whois.aunic.net"),
                  array("org.br","whois.nic.br"),
                  array("org.cn","whois.cnnic.net.cn"),
                  array("org.hk","whois.hknic.net.hk"),
                  array("org.lu","whois.dns.lu"),
                  array("org.ru","whois.ripn.ru"),
                  array("org.tw","whois.twnic.net"),
                  array("org.uk","whois.nic.uk"),
                  array("pl","nazgul.nask.waw.pl"),
                  array("pp.ru","whois.ripn.ru"),
                  array("ppg.br","whois.nic.br"),
                  array("pro.br","whois.nic.br"),
                  array("psi.br","whois.nic.br"),
                  array("psc.br","whois.nic.br"),
                  array("pt","whois.ripe.net"),
                  array("qh.cn","whois.cnnic.net.cn"),
                  array("qsl.br","whois.nic.br"),
                  array("rec.br","whois.nic.br"),
                  array("ro","whois.rotld.ro"),
                  array("ru","whois.ripn.ru"),
                  array("sc.cn","whois.cnnic.net.cn"),
                  array("sd.cn","whois.cnnic.net.cn"),
                  array("se","whois.nic-se.se"),
                  array("sg","whois.nic.net.sg"),
                  array("sh","whois.nic.sh"),
                  array("sh.cn","whois.cnnic.net.cn"),
                  array("si","whois.arnes.si"),
                  array("sk","whois.ripe.net"),
                  array("slg.br","whois.nic.br"),
                  array("sm","whois.ripe.net"),
                  array("sn.cn","whois.cnnic.net.cn"),
                  array("srv.br","whois.nic.br"),
                  array("st","whois.nic.st"),
                  array("sx.cn","whois.cnnic.net.cn"),
                  array("tc","whois.adamsnames.tc"),
                  array("th","whois.nic.uk"),
                  array("tj.cn","whois.cnnic.net.cn"),
                  array("tmp.br","whois.nic.br"),
                  array("to","whois.tonic.to"),
                  array("tr","whois.ripe.net"),
                  array("trd.br","whois.nic.br"),
                  array("tur.br","whois.nic.br"),
                  array("tv","whois.tv"),
                  array("tv.br","whois.nic.br"),
                  array("tw","whois.twnic.net"),
                  array("tw.cn","whois.cnnic.net.cn"),
                  array("uk","whois.thnic.net"),
                  array("va","whois.ripe.net"),
                  array("vet.br","whois.nic.br"),
                  array("vg","whois.adamsnames.tc"),
                  array("wattle.id.au","whois.aunic.net"),
                  array("ws","whois.worldsite.ws"),
                  array("xj.cn","whois.cnnic.net.cn"),
                  array("xz.cn","whois.cnnic.net.cn"),
                  array("yn.cn","whois.cnnic.net.cn"),
                  array("zlg.br","whois.nic.br"),
                  array("zj.cn","whois.cnnic.net.cn"),
                  array("nu","whois.nic.nu"),
                  array("ir","whois.nic.ir")
                  );
                  
                  $whocnt = count($whoisservers);
                  for ($x=0;$x<$whocnt;$x++){
                  	$artld = $whoisservers[$x][0];
                  	$tldlen = intval(0 - strlen($artld));
                  	if (substr($domain, $tldlen) == $artld) $whosrv = $whoisservers[$x][1];
                  }
                  return $whosrv;
                  }
                  
                  function lookup($dom){
                  	$lusrv = get_whois_server($dom);
                  	if (!$lusrv) return "";
                  
                  $fp = fsockopen($lusrv,43);
                  fputs($fp, "$dom\r\n");
                  $string="";
                  while(!feof($fp)){
                  	$string.= fgets($fp,128);
                  }
                  fclose($fp);
                  
                  $reg = "/Whois Server: (.*?)\n/i";
                  preg_match_all($reg, $string, $matches);
                  $secondtry = $matches[1][0];
                  
                  if ($secondtry){
                  	$fp = fsockopen($secondtry,43);
                  	fputs($fp, "$dom\r\n");
                  	$string="";
                  	while(!feof($fp)){
                  		$string.=fgets($fp,128);
                  	}
                  	fclose($fp);
                  }
                  #Copyright Info, do not remove.
                  return $string."<br>Powered By <a href='http://www.nukedweb.com/phpscripts/' target='_nukedweb'>phpGlobalWhois</a>";
                  }
                  ?>
                  <html>
                  <head>
                  <title>phpGlobalWhois</title>
                  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                  </head>
                  
                  <body bgcolor="#FFFFFF" text="#000000">
                  <form name="form1" method="post" action="example.php">
                    Domain: <input type="text" name="dom">
                    <input type="submit" name="Submit" value="Submit">
                  </form>
                  <?
                  if ($dom){
                  	$whoisresult = lookup($dom);
                  	#The PRE tags are there to display the results in web browsers without replacing \n with <br>..its just cleaner and quicker that way. ;)
                  	print "<pre>".$whoisresult."</pre>";
                  }
                  ?>
                  </body>
                  </html>
                  

                    Thank you all for your help, specially dear hand, I saw the code and I'll try to figure it out. Thanx for your help and have fun.

                      Nice script hand...

                      For people who arent sure - the file needs to be saved as example.php

                      As a very "MINOR" improvement to let you name the script to anything you want you could replace:

                      action="example.php"

                      with

                      action="<?PHP $PHP_SELF ?>"

                      People sharing these scripts is why I love this site so much 🙂

                        Write a Reply...