Display website information using Perl
Thu, 07/02/2013 - 17:34
This script will gather all the information like:
If you have any idea or wish to suggest code editing/addition please comment here.
- DNS Servers
- 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
- IP Address where hosted
#!/usr/bin/perl ########################################################### # Author: Sanjeev Kumar Jaiswal # Date: Feb, 2013 # Script: siteinfo.pl # Description: This script will print relevant information # for tha website passed while running the script through command line. # Like: Mail Servers, Name Servers, Google Page Rank, Alexa Rank, # Creation Date, Expiration Date, Domain Exists or not # One can tweak the script to get more information # like registrar info, contact details, email id of the site owner etc ######################################################################### use strict; use warnings; use lib '../lib'; use Net::DNS; use Net::Whois::Raw qw( whois ); use WWW::Google::PageRank; use LWP::Simple; my $res = Net::DNS::Resolver->new; # Perform a lookup, using the searchlist if appropriate. my $domain_name = $ARGV[0] or die "Please pass domain name at command line\n"; my $site = whois($domain_name); #Check if domain name exists or not before processing further die "$domain_name doesn't exists as of now, try some other domain\n" unless(domain_exists()); print "*-------------------------- Site Infor for $domain_name -----------------------*\n"; print "\n*-------------- Google Page Rank and Alexa Rank-------------------------*\n"; get_google_pagerank($domain_name); get_alexa_rank($domain_name); print "*-------------------------------------------------------------------------*\n"; print "\n*----------Mail Servers ------------*\n"; get_mail_server($domain_name); print "*-----------------------------------*\n"; print "\n*------------- Name Servers ------------------\n"; get_name_server($domain_name); print "*---------------------------------------------*\n"; print "\n*------------ Site's Other details ----------------*\n"; get_site_details(); print "*-----------------------------------------------------*\n"; ################ Subroutines ######################### #Checking Domain existense sub domain_exists{ return 0 if($site =~ m/No match for/igs); return 1; } # Prints Alexa Rank sub get_alexa_rank{ my $domain = shift; my $url = "http://www.alexa.com/siteinfo/$domain"; my $content = get($url); #Regular Expression to Find Global Rank my @alexa_rank = $content =~ m/globe-sm.jpg(.*?)"\/>\n(.*?)<\/div>/gis; print "Alexa Rank: $alexa_rank[1]\n"; } # Prints Google Page Rank sub get_google_pagerank{ my $domain_name = shift; my $page_rank = WWW::Google::PageRank->new(); my $rank = $page_rank->get("http://www.$domain_name"); print "Google Page Rank: $rank \n"; } # Prints Name Server for $domain_name sub get_name_server{ my $domain = shift; my $query = $res->query($domain, "NS"); if ($query) { foreach my $rr (grep { $_->type eq 'NS' } $query->answer) { print $rr->nsdname, "\n"; } } else { warn "query failed: ", $res->errorstring, "\n"; } } # prints mail server(s) list if any sub get_mail_server{ my $domain = shift; my @mx = mx($res, $domain); if(scalar @mx){ for (my $i=0; $i<=$#mx; $i++){ print "$mx[$i]->{'exchange'}\n"; } } else{ print "No Mail servers found for $domain\n"; } } sub get_site_details{ #Usually it will be in this format # Created on: 06-Jan-11 or Created on......: or Registration Date: # Expires on: 06-Jan-16 or Expiration Date: # Last Updated on: 16-Jan-13 my ($created_type) = $site =~ m/(Created|Registration\s+Date\s*:)(.*?).*/igs; my ($expire_type) = $site =~ m/(Expires|Expiration\s+Date\s*:)/igs; my ($update_type) = $site =~ m/(modified on)/igs; if($created_type && $created_type =~ m/registration/i) { my @created = $site =~ m/registration\s+date(.*?):\s*(.*?)\n+/sgi; print "Created on: $created[1]\n"; } if($created_type && $created_type =~ m/created/i){ my @created = $site =~ m/Create(.*?):\s*(.*?)\n+/sgi; print "Created on: $created[1]\n"; } if($expire_type && $expire_type =~ m/expiration/i){ my @expire = $site =~ m/expiration\s+date(.*?):\s*(.*?)\n+/sgi; print "Expires on: $expire[1]\n"; } if($expire_type && $expire_type =~ m/expires/i){ my @expire = $site =~ m/expires\s+on(.*?):\s*(.*?)\n+/sgi; print "Expires on: $expire[1]\n"; } if($update_type && $update_type =~ m/updated/i){ my @updated = $site =~ m/updated\s+on(.*?):\s*(.*?)\n+/igs; print "Last Updated on: $updated[1]\n"; } if($update_type && $update_type =~ m/modified/i){ my @updated = $site =~ m/modified\s+on(.*?):(.*?)\n+/igs; print "Last Updated on: $updated[1]\n"; } }
If you have any idea or wish to suggest code editing/addition please comment here.


