Skip to main content

Display website information using Perl

No replies
sanjeev's picture
Offline
Joined: 21 Feb 2011
This script will gather all the information like:
  • DNS Servers
  • IP Address
  • Mail Servers
  • Google Page Rank
  • Alexa Rank
  • Creation Date
  • Expiration Date

As of now we display only this information. This script may not work 100% for all domain names. And Creation, expiration date will not be displayed for websites which own its DNS servers like facebook.com, google.com. godaddy.com etc

This script is platform independent provide you have perl installed and have all the necessary modules installed :)

Later we may edit the script to get more information like :

  • Site Owner's Address
  • Site Owner's Email Id
  • Site Owner's Contant Number
  • Registrar Info
Here is the Perl Code :
  1.  
  2. #!/usr/bin/perl
  3. ###########################################################
  4. # Author: Sanjeev Kumar Jaiswal
  5. # Date: Feb, 2013
  6. # Script: siteinfo.pl
  7. # Description: This script will print relevant information
  8. # for tha website passed while running the script through command line.
  9. # Like: Mail Servers, Name Servers, Google Page Rank, Alexa Rank,
  10. # Creation Date, Expiration Date, Domain Exists or not
  11. # One can tweak the script to get more information
  12. # like registrar info, contact details, email id of the site owner etc
  13. #########################################################################
  14. use strict;
  15. use warnings;
  16. use lib '../lib';
  17. use Net::DNS;
  18. use Net::Whois::Raw qw( whois );
  19. use WWW::Google::PageRank;
  20. use LWP::Simple;
  21.  
  22. my $res = Net::DNS::Resolver->new;
  23.  
  24. # Perform a lookup, using the searchlist if appropriate.
  25. my $domain_name = $ARGV[0] or die "Please pass domain name at command line\n";
  26.  
  27. my $site = whois($domain_name);
  28.  
  29. #Check if domain name exists or not before processing further
  30. die "$domain_name doesn't exists as of now, try some other domain\n" unless(domain_exists());
  31.  
  32. print "*-------------------------- Site Infor for $domain_name -----------------------*\n";
  33.  
  34. print "\n*-------------- Google Page Rank and Alexa Rank-------------------------*\n";
  35. get_google_pagerank($domain_name);
  36. get_alexa_rank($domain_name);
  37. print "*-------------------------------------------------------------------------*\n";
  38.  
  39.  
  40. print "\n*----------Mail Servers ------------*\n";
  41. get_mail_server($domain_name);
  42. print "*-----------------------------------*\n";
  43.  
  44. print "\n*------------- Name Servers ------------------\n";
  45. get_name_server($domain_name);
  46. get_ip_address($domain_name);
  47. print "*---------------------------------------------*\n";
  48.  
  49.  
  50. print "\n*------------ Site's Other details ----------------*\n";
  51. get_site_details();
  52. print "*-----------------------------------------------------*\n";
  53.  
  54.  
  55. ################ Subroutines #########################
  56. #Checking Domain existense
  57. sub domain_exists{
  58. return 0 if($site =~ m/No match for/igs);
  59. return 1;
  60. }
  61.  
  62. # Prints Alexa Rank
  63. sub get_alexa_rank{
  64. my $domain = shift;
  65. my $url = "http://www.alexa.com/siteinfo/$domain";
  66. my $content = get($url);
  67.  
  68.  
  69. #Regular Expression to Find Global Rank
  70. my @alexa_rank = $content =~ m/globe-sm.jpg(.*?)"\/>\n(.*?)<\/div>/gis;
  71. print "Alexa Rank: $alexa_rank[1]\n";
  72.  
  73. }
  74.  
  75. # Prints Google Page Rank
  76. sub get_google_pagerank{
  77. my $domain_name = shift;
  78. my $page_rank = WWW::Google::PageRank->new();
  79. my $rank = $page_rank->get("http://www.$domain_name");
  80. print "Google Page Rank: $rank \n";
  81. }
  82.  
  83. # Prints Name Server for $domain_name
  84. sub get_name_server{
  85. my $domain = shift;
  86. my $query = $res->query($domain, "NS");
  87. if ($query) {
  88. foreach my $rr (grep { $_->type eq 'NS' } $query->answer) {
  89. print $rr->nsdname, "\n";
  90. }
  91. }
  92. else {
  93. warn "query failed: ", $res->errorstring, "\n";
  94. }
  95. }
  96.  
  97. #Prints IP Address of a given website
  98. sub get_ip_address{
  99. my $domain = shift;
  100. my $resolver = Net::DNS::Resolver->new();
  101. my $response = $resolver->send("$domain", "A");
  102. my @rr = grep { $_->type eq "A" } $response->answer;
  103. my $ip = $rr[0]->address;
  104. print "IP Address: $ip\n";
  105. }
  106.  
  107. # prints mail server(s) list if any
  108. sub get_mail_server{
  109. my $domain = shift;
  110. my @mx = mx($res, $domain);
  111.  
  112. if(scalar @mx){
  113. for (my $i=0; $i<=$#mx; $i++){
  114. print "$mx[$i]->{'exchange'}\n";
  115. }
  116. }
  117. else{
  118. print "No Mail servers found for $domain\n";
  119. }
  120. }
  121.  
  122. sub get_site_details{
  123.  
  124. #Usually it will be in this format
  125. # Created on: 06-Jan-11 or Created on......: or Registration Date:
  126. # Expires on: 06-Jan-16 or Expiration Date:
  127. # Last Updated on: 16-Jan-13
  128.  
  129. my ($created_type) = $site =~ m/(Created|Registration\s+Date\s*:)(.*?).*/igs;
  130. my ($expire_type) = $site =~ m/(Expires|Expiration\s+Date\s*:)/igs;
  131. my ($update_type) = $site =~ m/(modified on)/igs;
  132.  
  133. if($created_type && $created_type =~ m/registration/i) {
  134. my @created = $site =~ m/registration\s+date(.*?):\s*(.*?)\n+/sgi;
  135. print "Created on: $created[1]\n";
  136. }
  137.  
  138. if($created_type && $created_type =~ m/created/i){
  139. my @created = $site =~ m/Create(.*?):\s*(.*?)\n+/sgi;
  140. print "Created on: $created[1]\n";
  141. }
  142.  
  143. if($expire_type && $expire_type =~ m/expiration/i){
  144. my @expire = $site =~ m/expiration\s+date(.*?):\s*(.*?)\n+/sgi;
  145. print "Expires on: $expire[1]\n";
  146. }
  147.  
  148. if($expire_type && $expire_type =~ m/expires/i){
  149. my @expire = $site =~ m/expires\s+on(.*?):\s*(.*?)\n+/sgi;
  150. print "Expires on: $expire[1]\n";
  151. }
  152.  
  153. if($update_type && $update_type =~ m/updated/i){
  154. my @updated = $site =~ m/updated\s+on(.*?):\s*(.*?)\n+/igs;
  155. print "Last Updated on: $updated[1]\n";
  156. }
  157.  
  158. if($update_type && $update_type =~ m/modified/i){
  159. my @updated = $site =~ m/modified\s+on(.*?):(.*?)\n+/igs;
  160. print "Last Updated on: $updated[1]\n";
  161. }
  162. }


If you have any idea or wish to suggest code editing/addition please comment here.
Update Code to print IP Address also.

Follow us at :
Facebook | Twitter
########### Give me the right place to stand, I shall move the earth. #################

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.