I can vouch that gethostbyname will use the hosts file on Linux.

This one-liner resolves a hostname to an IPv4 address:

perl -w -MSocket -e 'my $pip=gethostbyname("www.google.com");my $ip=in +et_ntoa($pip);print $ip,"\n";'

"Normal" resolution via DNS returns: 142.250.72.132

If I add this line to /etc/hosts:
127.0.0.1 www.google.com

The above one-liner returns: 127.0.0.1

So on Linux, Perl will use the hosts file (Well, technically, it use the resolver library). However, I don't have a Windows machine with Perl handy to test with so I do not know if it will also work there. No good reason it shouldn't.


In reply to Re: Strawberry Perl: Windows hosts file not working? by enemyofthestate
in thread Strawberry Perl: Windows hosts file not working? by sectokia

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.