A programming & designing blog!

LightBlog
Responsive Ads Here

Friday, November 1, 2013

Domain Whois Lookup with PHP

Whois is a way to check ownership of a domain name. We can know ownership information like owner name, address, etc. from whois record.

There are many ways are available to check whois recode. In Linux system you can run whois command to check whois recode. We can also build our won application to fetch whois recode. In this post I will show you how can can get whois recode with pure php code.

Download Source

The Whois Class

/**
* Domain Whois with PHP & CURL
* @author Resalat Haque
* @link http://www.w3bees.com
*/
class Whois
{
  /**
   * whois servers list
   * 
   * @var array
   */
  var $whois_servers = array(
    'com' => 'whois.crsnic.net',
    'net' => 'whois.verisign-grs.com',
    'org' => 'whois.pir.org',
    'info' => 'whois.afilias.info',
    'biz' => 'whois.neulevel.biz',
    'us' => 'whois.nic.us',
    'uk' => 'whois.nic.uk',
    'ca' => 'whois.cira.ca',
    'tel' => 'whois.nic.tel',
    'ie' => 'whois.iedr.ie',
    'it' => 'whois.nic.it',
    'li' => 'whois.nic.li',
    'no' => 'whois.norid.no',
    'cc' => 'whois.nic.cc',
    'eu' => 'whois.eu',
    'nu' => 'whois.nic.nu',
    'au' => 'whois.aunic.net',
    'de' => 'whois.denic.de',
    'ws' => 'whois.worldsite.ws',
    'sc' => 'whois2.afilias-grs.net',
    'mobi' => 'whois.dotmobiregistry.net',
    'pro' => 'whois.registrypro.pro',
    'edu' => 'whois.educause.net',
    'tv' => 'whois.nic.tv',
    'travel' => 'whois.nic.travel',
    'name' => 'whois.nic.name',
    'in' => 'whois.inregistry.net',
    'me' => 'whois.nic.me',
    'at' => 'whois.nic.at',
    'be' => 'whois.dns.be',
    'cn' => 'whois.cnnic.cn',
    'asia' => 'whois.nic.asia',
    'ru' => 'whois.ripn.ru',
    'ro' => 'whois.rotld.ro',
    'aero' => 'whois.aero',
    'fr' => 'whois.nic.fr',
    'se' => 'whois.iis.se',
    'nl' => 'whois.sidn.nl',
    'nz' => 'whois.srs.net.nz',
    'mx' => 'whois.nic.mx',
    'tw' => 'whois.apnic.net',
    'ch' => 'whois.nic.ch',
    'hk' => 'whois.hknic.net.hk',
    'ac' => 'whois.nic.ac',
    'ae' => 'whois.nic.ae',
    'af' => 'whois.nic.af',
    'ag' => 'whois.nic.ag',
    'al' => 'whois.ripe.net',
    'am' => 'whois.amnic.net',
    'as' => 'whois.nic.as',
    'az' => 'whois.ripe.net',
    'ba' => 'whois.ripe.net',
    'bg' => 'whois.register.bg',
    'bi' => 'whois.nic.bi',
    'bj' => 'www.nic.bj',
    'br' => 'whois.nic.br',
    'bt' => 'whois.netnames.net',
    'by' => 'whois.ripe.net',
    'bz' => 'whois.belizenic.bz',
    'cd' => 'whois.nic.cd',
    'ck' => 'whois.nic.ck',
    'cl' => 'nic.cl',
    'coop' => 'whois.nic.coop',
    'cx' => 'whois.nic.cx',
    'cy' => 'whois.ripe.net',
    'cz' => 'whois.nic.cz',
    'dk' => 'whois.dk-hostmaster.dk',
    'dm' => 'whois.nic.cx',
    'dz' => 'whois.ripe.net',
    'ee' => 'whois.eenet.ee',
    'eg' => 'whois.ripe.net',
    'es' => 'whois.ripe.net',
    'fi' => 'whois.ficora.fi',
    'fo' => 'whois.ripe.net',
    'gb' => 'whois.ripe.net',
    'ge' => 'whois.ripe.net',
    'gl' => 'whois.ripe.net',
    'gm' => 'whois.ripe.net',
    'gov' => 'whois.nic.gov',
    'gr' => 'whois.ripe.net',
    'gs' => 'whois.adamsnames.tc',
    'hm' => 'whois.registry.hm',
    'hn' => 'whois2.afilias-grs.net',
    'hr' => 'whois.ripe.net',
    'hu' => 'whois.ripe.net',
    'il' => 'whois.isoc.org.il',
    'int' => 'whois.isi.edu',
    'iq' => 'vrx.net',
    'ir' => 'whois.nic.ir',
    'is' => 'whois.isnic.is',
    'je' => 'whois.je',
    'jp' => 'whois.jprs.jp',
    'kg' => 'whois.domain.kg',
    'kr' => 'whois.nic.or.kr',
    'la' => 'whois2.afilias-grs.net',
    'lt' => 'whois.domreg.lt',
    'lu' => 'whois.restena.lu',
    'lv' => 'whois.nic.lv',
    'ly' => 'whois.lydomains.com',
    'ma' => 'whois.iam.net.ma',
    'mc' => 'whois.ripe.net',
    'md' => 'whois.nic.md',
    'mil' => 'whois.nic.mil',
    'mk' => 'whois.ripe.net',
    'ms' => 'whois.nic.ms',
    'mt' => 'whois.ripe.net',
    'mu' => 'whois.nic.mu',
    'my' => 'whois.mynic.net.my',
    'nf' => 'whois.nic.cx',
    'pl' => 'whois.dns.pl',
    'pr' => 'whois.nic.pr',
    'pt' => 'whois.dns.pt',
    'sa' => 'saudinic.net.sa',
    'sb' => 'whois.nic.net.sb',
    'sg' => 'whois.nic.net.sg',
    'sh' => 'whois.nic.sh',
    'si' => 'whois.arnes.si',
    'sk' => 'whois.sk-nic.sk',
    'sm' => 'whois.ripe.net',
    'st' => 'whois.nic.st',
    'su' => 'whois.ripn.net',
    'tc' => 'whois.adamsnames.tc',
    'tf' => 'whois.nic.tf',
    'th' => 'whois.thnic.net',
    'tj' => 'whois.nic.tj',
    'tk' => 'whois.nic.tk',
    'tl' => 'whois.domains.tl',
    'tm' => 'whois.nic.tm',
    'tn' => 'whois.ripe.net',
    'to' => 'whois.tonic.to',
    'tp' => 'whois.domains.
    tl',
    'tr' => 'whois.nic.tr',
    'ua' => 'whois.ripe.net',
    'uy' => 'nic.uy',
    'uz' => 'whois.cctld.uz',
    'va' => 'whois.ripe.net',
    'vc' => 'whois2.afilias-grs.net',
    've' => 'whois.nic.ve',
    'vg' => 'whois.adamsnames.tc',
    'xxx' => 'whois.nic.xxx',
    'yu' => 'whois.ripe.net'
    );
  
  /**
   * domain
   * @var string
   */
  var $domain;

  /**
   * TLD
   * 
   * @var string
   */
  var $tld;

  /**
   * @param str $url
   * 
   * @return void
   */
  function __construct($domain)
  {
    $this->domain = $domain;
    $this->tld = $this->getTld($this->domain);
  }

  /**
   * get whois recode
   * 
   * @return string
   */
  function get()
  {
    if (array_key_exists($this->tld, $this->whois_servers))
    {
      $server = $this->whois_servers[$this->tld];
      return $this->sendRequest($server, $this->domain);
    }
    else
    {
      return 'Unsupported domain name';
    }
  }

  /**
   * get TLD from domain name
   * 
   * @param string $doamin
   * @return string
   */
  function getTLD($domain)
  {
    $domain = explode('.', $domain);
      $lst = count($domain) - 1;
      return isset($domain[$lst]) ? $domain[$lst] : '';
  }

  /**
   * send request to the whois server
   * 
   * @param string $server
   * @param string $domain
   * 
   * @return string
   */
  function sendRequest($server, $doamin)
  {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $server);
    curl_setopt($ch, CURLOPT_PORT, 43);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $doamin . "\r\n");
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
  }
}

Usage

$whois = new Whois('w3bees.com');
echo '<pre>'. $whois->get() .'</pre>';

89 comments:

  1. Replies
    1. dongtam
      mu moi ra hom nay
      tim phong tro
      http://nhatroso.com/
      nhạc sàn
      tổng đài tư vấn luật
      văn phòng luật hà nội
      tổng đài tư vấn luật
      thành lập công ty trọn gói
      http://we-cooking.com/
      chém gió
      trung tâm tiếng anhsắc mặt của hắn liền biến đổi lớn.

      Một mảng hắc mang tràn ngập giống như là biển gầm đánh về phía Hỏa Lão, đồng thời thân hình của Địa Ma Lão Nhân một lần nữa lui về phía dưới.

      Địa Ma Lão Nhân hiểu rõ trong lòng, mình mặc dù có thực lực bát tinh Đấu Tôn đỉnh phong nhưng so với cửu tinh Đấu Tôn thì vẫn còn kém xa, hai thực lực cách biệt một trời một vực.

      - Xoẹt.

      Một mảng hồng mang nóng bỏng hiện lên, Nhạc Thành đã cảm nhận thấy Hỏa Lão đã khôi phục thực lực tới cửu tinh Đấu Tôn, ngọn lửa trên người cũng ngày càng trở nên cường hãn.

      - Xoẹt xoẹt.

      Hai luồng lực lượng dây dưa một chỗ, Hỏa Lão ngưng tụ hỏa diễm cho thấy uy lực mạnh hơn rất nhi ào, hú.

      Cùng với việc Hỏa Lão và Địa Ma Lão Nhân triển khai công kích, Cự Viên Tộc ma thú cũng công kích bảy con ma thú của Hắc Ám Thần Điện.

      Kim Cương tộc trưởng chọn hai con ma thú cấp tám trung kỳ, với thực lực của Kim Cương tộc trưởng đối với mấy con ma thú này không hề có chút vấn đề gì.

      Delete
  2. Thanks for your information. There are lot of ways available to check whois history. I have checked whois information from this site Whoisxy.com

    ReplyDelete
  3. thank you very much for this script
    is it possible to connect to whois server through a proxy ??

    ReplyDelete
  4. Is there any further reading you would recommend on this?

    Anne Cole

    who is visiting my website

    ReplyDelete
    Replies
    1. Nicely explained. Here you described the well written article from your in-depth knowledge. Truly impressive and nice information

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

      Delete
  5. Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.

      ES6 Online Training JavaScript Training Courses JavaScript Training Courses | Angular 4 Online Training Angular 4 Online Training

      Delete
  6. Hi. It is not working for DE-Domains?

    ReplyDelete
  7. These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post. Your articles really impressed for me,because of all information so nice.

    SAP training in Chennai

    ReplyDelete
  8. I love your blog..Have a great day
    http://crackslink.com/kasper-antivirus-2016-crack/

    ReplyDelete
  9. doesnt work for the server whois.na-nic.com.na, i added is to the array

    ReplyDelete
  10. doesnt work for the server whois.na-nic.com.na, i added is to the array

    ReplyDelete
  11. Great post.
    It really helped me to learn something new. So thanks.
    Linux training in Bangalore

    ReplyDelete
  12. This is the precise weblog for anybody who needs to seek information about this topic.You positively put a brand new spin on a subject that has been written about for years. Nice stuff simply nice!

    ReplyDelete
  13. There are no words to encourage about your post. It’s not only helpful to me. All of the small business can gain lots benefits by read your post.
    android training in Bangalore | Big data analytics training in Bangalore

    ReplyDelete
  14. Yeah. I am very interesting to start my website domain using PHP. Because, today lots of small business is working based on PHP. Moreover, your source code will give good support to me.

    PHP Training in Bangalore

    ReplyDelete
  15. Very informative post
    if any one learn php Programming join our Best php training Institute in Delhi Thank You Keep Posting

    ReplyDelete
  16. Really useful blog. Thank you for the post

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. what is .co indian Whois server

    ReplyDelete
  19. Thanks for your useful information. I learned new things from this blog. PHP training in bangalore

    ReplyDelete
  20. Thanks for sharing this useful information. Nice post it will help to improve technical knowledge. Spring training in Bangalore

    ReplyDelete
  21. Wow..great job. keep on sharing like this useful blogs.best angularjs training in Bangalore

    ReplyDelete
  22. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted "Oracle Training in Bangalore".

    ReplyDelete
  23. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site. rprogramming training in bangalore

    ReplyDelete
  24. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    java-training in chennai

    ReplyDelete
  25. Thanks for your informative article. Java is most popular programming language used for creating rich enterprise, desktop and web applications. Keep on updating your blog with such informative post.
    JAVA Training in Chennai|JAVA Course in Chennai|Best JAVA Training in Chennai

    ReplyDelete
  26. Quite Interesting post!!! Thanks for posting such a useful post. I wish to read your upcoming post to enhance my skill set, keep blogging.
    Regards,

    Data Science Course in Chennai

    ReplyDelete
  27. Nice piece of information on HTML5. With the expansion of smartphones and other portable gadgets, the demand for responsive website design that go comfy on all devices keeps on increasing. This leads to invention and expansion of HTM5 web technology.PHP Training in Chennai

    ReplyDelete
  28. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    python-training in chennai

    ReplyDelete
  29. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    AWS TRAINING IN BANGALORE

    ReplyDelete
  30. It has been simply incredibly generous with you to provide openly
    what exactly many individuals would’ve marketed for an eBook to end
    up making some cash for their end, primarily given that you could
    have tried it in the event you wanted.


    aws training in chennai



    aws training in bangalore

    ReplyDelete
  31. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.digital marketing training in chennai

    ReplyDelete
  32. Thanks a lot very much for the high your blog post quality and results-oriented help. I won’t think twice to endorse to anybody who wants and needs support about this area. hadoop training in bangalore

    ReplyDelete
  33. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    python training in bangalore

    ReplyDelete
  34. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    data science training in chennai

    ReplyDelete
  35. There are numerous websites that use exact same code and give us the details upfront.

    Great working and we can use the same in other server side technologies like Best Node JS training in Chennai

    Thanks for the insights. :)

    ReplyDelete
  36. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

    oracle training in Bangalore

    ReplyDelete
  37. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

    oracle training in Bangalore

    ReplyDelete
  38. Thanks a lot very much for the high your blog post quality and results-oriented help. I won’t think twice to endorse to anybody who wants and needs support about this area.
    java training in chennai

    ReplyDelete
  39. Very nice information its very useful to read your blog. We provide best austeretech.com/digital-transformation Digital Transformation Services

    ReplyDelete
  40. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.

    NO.1 APP DEVELOPMENT SERVICES | MASSIL TECHNOLOGIES

    ReplyDelete
  41. REALLY VERY EXCELLENT INFORMATION. I AM VERY GLAD TO SEE YOUR BLOG FOR THIS INFORMATION. THANKS FOR SHARING. KEEP UPDATING.

    NO.1 IOT Services | INTERNET OF THINGS | Best IOT Services |

    ReplyDelete
  42. HiAdmin,
    I go through your blog and it’s really awesome. Keep updating your site with such useful post. Also include Rss feed of your blog

    performance testing training in chennai | Best QTP Training Center in Chennai

    ReplyDelete
  43. Great information about PHP, very helpful information. Thanks for shring.
    Best Mobility Services | Austere Technologies

    ReplyDelete
  44. Thanks for the complete guidance on domain whois lookup. Hope your article has reserve a unique place among blog readers.
    PHP Training
    PHP Institutes in Chennai

    ReplyDelete
  45. Excellent information with a great explanation. Thanks for sharing, keep updating.

    NO.1 CLOUD SERVICES | Oracle Cloud PAAS | MASSIL TECHNOLOGIES

    ReplyDelete
  46. Thanks for Sharing a Great Post.
    trainingatdelhi well-equipped Best 6 Weeks training in Cloud Computing in Delhi provides real time projects along with 6 weeks Cloud Computing placement training. Cloud Computing Training in Delhi has been designed as per latest industry trends and keeping in mind the advanced Cloud Computing course content and syllabus based on the professional requirement of the student.
    BEST Cloud Computing TRAINING IN DELHI
    6 Weeks Summer Internship in Cloud Computing in Delhi

    ReplyDelete
  47. It is very informative Useful Post.
    Kvch Delhi is an growing institute for Summer training in PHP in Delhi to build their career in web technology and IT industry. We are among the few PHP training institutes in Delhi having roots in software and web technology development. We are division of our well-known web development and promotion venture Wings IT Solutions. We are providing 6 Weeks Summer Internship in PHP in Delhi with Live Project.
    Best 6 Weeks training in PHP in Delhi
    6 Weeks Summer Internship in PHP in Delhi

    ReplyDelete



  48. Best Mobility Services
    Very good article. this bolg article are good and keep sharing more article.

    ReplyDelete
  49. Im no expert, but I believe you just made an excellent You certainly understand what youre speaking about, and I can truly get behind that.
    Android Training in Chennai|Android Training

    ReplyDelete
  50. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    rpa training in chennai

    ReplyDelete
  51. Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.

    Application Quality Management Services | Austere Technologies

    ReplyDelete
  52. Great article, really very helpful content you made. Thank you, keep sharing.

    Digital Transformation Servicces | Austere Technology Solutions

    ReplyDelete
  53. I strongly believe that there will be great opportunities for those who looked into this area...
    Best Online Software Training Institute | PHP Training

    ReplyDelete