Tag Archives: dns

Resolve IP address from hostname with perl.

Here is a small section of perl code that I stumbled upon that resolves an IP from a supplied hostname. Written by detour@metalshell.com. use Socket; use strict;   sub hostname { my (@bytes, @octets, $packedaddr, $raw_addr, $host_name, $ip); if($_[0] =~ /[a-zA-Z]/g) { $raw_addr = (gethostbyname($_[0]))[4]; @octets = unpack("C4", $raw_addr); $host_name = join(".", @octets); } else [...]
Posted in Programming, Webhosting | Also tagged | Leave a comment