develooper Front page | perl.beginners | Postings from December 2002

Re: Resolving DNS/IP

Thread Previous
From:
dan
Date:
December 26, 2002 18:10
Subject:
Re: Resolving DNS/IP
Message ID:
20021227021004.69827.qmail@onion.perl.org
oo it worked, cheers :)

dan

"Peter Scott" <peter@PSDT.com> wrote in message
news:20021224155212.44426.qmail@onion.perl.org...
> In article <20021224141301.65781.qmail@onion.perl.org>,
>  dan@abovenet.org (Dan) writes:
> >I need my program to resolve hosts to IP's, and vice versa. I came across
> >the Net::DNS module on CPAN, but have no idea how to just give it a host,
> >and get it to return an IP, and vice versa. The help for it doesn't make
> >sense to me either :(
>
> You don't need no module, son, it's easy enough without one:
>
> Single IP:
>
> $ perl -MSocket -le 'print inet_ntoa(scalar gethostbyname("cnn.com"))'
> 64.236.24.12
>
> All IPs (if you care):
>
> $ perl -MSocket -le '@x = gethostbyname("cnn.com"); \
> print inet_ntoa($_) for @x[4..$#x]'
> 64.236.24.20
> 64.236.24.28
> 64.236.16.20
> 64.236.16.52
> 64.236.16.84
> 64.236.16.116
> 64.236.24.4
> 64.236.24.12
>
> --
> Peter Scott
> http://www.perldebugged.com



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About