On Tue, 20 Oct 2009 16:34 +0200, "rocku" <rock...@gmail.com> wrote:
> Hello,
> I need to resolve a hostname by a specified nameserver. Currently I am 
> using nslookup throught backticks, but it's output differs slightly 
> between Windows versions and is hard to parse. I wanted to use Socket 
> and something like inet_ntoa(inet_aton('hostname')) but this way I have 
> no option to specify the nameserver to query. I am aware about Net::DNS, 
> but unfortunately I cannot use it because it's not standard in 
> ActivePerl 5.10. An ideal solution would be some WMI function, but I 
> cannot find any for the task. Maybe using Win32::API?
> 
> So my question is - how to query a specific nameserver about a DNS 'A' 
> record?
> 
> -- 
> rocku

You sure don't need Net::DNS for that.

Here is a very simple script that list all ip's associated to a hostname (or 
any name known on your DNS).
I use the same script on windows or linux it just work asis :

--------------------------------------------------------------------------------------------------
#!/usr/bin/perl -w
#------------------#-------------------------------------------------------------
# Param 1 = windows name of a machine
# Return   = IP or list of IP of that machine
#--------------------------------------------------------------------------------
#
#

use Socket;

my $poste = $ARGV[0];

if (!$poste) {$poste = "localhost";}

# gethostbyname method

    my $host = (gethostbyname ($poste))[0];
    print "================\n";
    printf "Adresse(s) IP de $host\n";
    my @addr = gethostbyname ($host);
    splice @addr, 0, 4;
    print "================\n";
    foreach (@addr) {
        printf "\t%s\n", &inet_ntoa ($_);
    }
---------------------------------------------------------------------------------------------
I wish to give credit to an unknow author on PerlMonks ( 
http://www.perlmonks.org/ )
from wich I took inspiration and some lines of code few years ago.

Good luck,

           BT


                                          
_________________________________________________________________
Une foule d’offres Windows 7 fantastiques, toutes à un endroit pratique. 
Trouvez dès maintenant l’aubaine idéale pour vous.
http://go.microsoft.com/?linkid=9691643
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to