Folks-

Kudos to kyle++ for a bunch of great ideas, particularly using inet_ntoa() - I had no idea...

Here's the answer to your question on why I need this...

The reason I need this is to run a command on remote machines, which needs the destination IP address (not the host name) in dotted notation, as a command line argument. The destination IP address is different for each remote machine, but is contained in either /etc/hosts, or in DNS, under a common host alias. My current solution is shown is this shell script fragment:
DESTIP=`perl-one-liner("common_host_alias")` remote_command -IP $DESTIP

ikegami++ as always. I've learned something new again (but don't yet understand). I do understand why

inet_ntoa(gethostbyname("www.google.com"))
gives me a usage error, but I don't understand why adding the "". makes it work
inet_ntoa("".gethostbyname("www.google.com"))
Unless this is some new form of black magic, it seems that you're simply adding a null in front of that which is returned by gethostbyname(). Why would that have an effect?

Lastly, jwkrahn++ for pointing out the unix host(1) command. Unfortunately, the box I'm running this on does not have the command installed.

Thanks

-Craig


In reply to Re: gethostbyname one-liner: Improvements? by cmv
in thread gethostbyname one-liner: Improvements? by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.