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

Re: Resolving DNS/IP

Thread Previous | Thread Next
December 24, 2002 07:52
Re: Resolving DNS/IP
Message ID:
In article <>, (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(""))'

All IPs (if you care):

	$ perl -MSocket -le '@x = gethostbyname(""); \
		print inet_ntoa($_) for @x[4..$#x]'

Peter Scott

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About