示例
以下是显示其基本用法的示例代码-
while( ($name, $aliases, $addrtype, $length, @addrs) = gethostent() ) {
print "Name = $name\n";
print "Aliases = $aliases\n";
print "Addr Type = $addrtype\n";
print "Length = $length\n";
print "Addrs = @addrs\n";
}
sethostent(1);
while( ($name, $aliases, $addrtype, $length, @addrs) = gethostent() ) {
print "Name = $name\n";
print "Aliases = $aliases\n";
print "Addr Type = $addrtype\n";
print "Length = $length\n";
print "Addrs = @addrs\n";
}
endhostent(); # Closes the database;
执行以上代码后,将产生以下结果--
Name = ip-50-62-147-141.ip.secureserver.net
Aliases = ip-50-62-147-141 localhost.secureserver.net localhost.localdomain localhost
Addr Type = 2
Length = 4
Addrs =
Name = ip-50-62-147-141.ip.secureserver.net
Aliases = ip-50-62-147-141 localhost.secureserver.net localhost.localdomain localhost
Addr Type = 2
Length = 4
Addrs =