Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Dns lookups

by hippo (Abbot)
on Dec 11, 2013 at 17:04 UTC ( #1066661=note: print w/replies, xml ) Need Help??


in reply to Dns lookups

Any reason not to use gethostbyname() instead?

perl -MSocket -e '@h=gethostbyname($_) and print "$_\n".inet_ntoa($h[4])."\n\n" for @ARGV;' perlmonks.org bing.com example.com

Still no good for IPv6, obviously, but a bit less wheel reinvention.

Replies are listed 'Best First'.
Re^2: Dns lookups
by perlaintdead (Scribe) on Dec 11, 2013 at 23:17 UTC

    haha. yeah i guess i should have looked into that module a bit more. I was just using what i was familiar with; needed something quick and dirty.

      and also you don't need those parens for gethostbyname

Re^2: Dns lookups
by perlaintdead (Scribe) on Dec 12, 2013 at 00:47 UTC

    you can also get rid of that pesky array

    use Socket;print "$_\n".inet_ntoa((gethostbyname$_)[4])."\n\n" for @AR +GV;

      The array is there to cope with the possibility of an unresolvable host. If you try your example above with args like

      ./pllookup.pl dklghslfhslgshj.com foo.com

      the unresolvability of dklghslfhslgshj.com would cause it to die on the first argument, whereas with the array it will just skip that and carry on to the remaining args. To my mind that's a better UX but others may disagree.

        The golfer in me couldn't resist

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1066661]
help
Chatterbox?
[corenth]: Good morning (in my neck of the woods)
[Cosmic37]: hello perly kings and queens
[jedikaiti]: 'ello Monks
[Cosmic37]: and monkeys too...
[Cosmic37]: is anyone doing machine learning with Perl?
[Cosmic37]: I was using gneural code in C and it was interesting but did not have back propagation for neural networks
[corenth]: Cosmic, poking at it, but not really.
[Cosmic37]: I read that its possible to use the FANN library with Perl so I might try that now...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2018-02-20 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (274 votes). Check out past polls.

    Notices?