in reply to Strawberry Perl: Windows hosts file not working?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strawberry Perl: Windows hosts file not working?
by soonix (Chancellor) on Feb 14, 2022 at 07:47 UTC | |
by enemyofthestate (Monk) on Feb 14, 2022 at 14:45 UTC | |
|
Re^2: Strawberry Perl: Windows hosts file not working?
by syphilis (Archbishop) on Feb 14, 2022 at 00:03 UTC | |
by LanX (Saint) on Feb 14, 2022 at 01:02 UTC | |
by syphilis (Archbishop) on Feb 14, 2022 at 03:46 UTC |