Click to See Complete Forum and Search --> : get server ip by it's domain name
Ultimater
10-14-2005, 03:37 PM
I think I recall a function in Perl that can preform a DNS look up on a domain and return it's IP address. Let's say for example I want to get the IP Address of "http://www.yahoo.com" then the function would preform a DNS look up and return 68.142.197.65. Thanks in advance, it would be so cool if I can find that function again so I can make a JavaScript bookmarklet to work on any site and alert it's IP Address.
The simplest method is to just open a socket.
#!/usr/bin/perl
use strict;
use IO::Socket;
use warnings FATAL => 'all';
my $hostname = "www.yahoo.com";
my $addr = inet_ntoa((gethostbyname($hostname))[4]);
print "Content-Type: text/html\n\n";
print "$addr\n";
This will work on named machines. For other un-named machines or servers behind routers and such, other methods are required.
Ultimater
10-14-2005, 08:20 PM
Thank You CyCo!
That code worked nicely :)
I revised it to suit my needs like so:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use IO::Socket;
print header;
unless(param("host")){print "\r\n";exit;}
my $hostname =param("host");
my $addr = inet_ntoa((gethostbyname($hostname))[4]);
=for comment
DomainName="http://www.yahoo.com";
IPAddress="68.142.197.65";
=cut
print "DomainName=\"".$hostname."\";\r\n";
print "IPAddress=\"".$addr."\";\r\n";
__END__
and now I can make use of a bookmarklet:
javascript:void(function(){location.href="http://www.aplustv.com/cgi-bin/public_stuff/getIP.pl?host="+location.hostname;}())
I should enhance the bookmarklet to make it easier to use with more functionality :)