Bracing against the wind  
www.documentroot.com  

Wednesday, February 29, 2012

gethostbyname command line

Pasteable script below. I can't believe this doesn't exist. No command line tool to get a host name using the resolver on linux?


#!/usr/bin/perl
use Socket;

$host = shift @ARGV;
die("usage: gethostbyname hostname\n") unless(defined($host));

$packed_ip = gethostbyname($host);

if (defined $packed_ip) {
$ip_address = inet_ntoa($packed_ip);
print "$ip_address\n";
exit 0
} else {
warn "$host not found\n";
exit 1
}

[View/Post Comments] [Digg] [Del.icio.us] [Stumble]

Home | Email me when this weblog updates: | View Archive

(C) 2002 Erik Aronesty/DocumentRoot.Com. Right to copy, without attribution, is given freely to anyone for any reason.


Listed on BlogShares | Bloghop: the best pretty good | Blogarama | Technorati | Blogwise