Here’s one way to do it.
foreach $host (@ARGV) { ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($host); print "$host:\n"; foreach $a (@addrs) { print join(".", unpack("C4", $a)), "\n"; } }This code just takes a list of machine names, iterates over them, calling
get-hostbyname()for each one. We then enumerate each of the addresses, printing them out in dotted decimal notation.Here’s one way to do it:
use Win32::Registry; $p = shift || die "usage: $0 path"; # strip leading backslashes $p =~ s#^\\##; $main::HKEY_LOCAL_MACHINE->Open($p, $key) || die "Open: $!"; $key->GetValues(\%vals); # get values -hash ref foreach $k (keys %vals) { $key = $vals{$k}; print "$$key[0] = $$key[2]\n"; }This code takes a path relative to HKEY_LOCAL_MACHINE (something like SOFTWARE\ActiveWare\Perl5) and strips beginning backslashes, if there are any. It opens the key using the precreated HKEY_LOCAL_MACHINE key. It then calls GetValues (passing it a reference to a hash; see Chapter 18, for more on references). The code then enumerates over the keys of the hash, printing them. Each value consists of a reference to a list with three items, so we assign the list reference to
$key. We then have to dereference$keyin order to access its values; we do so with the$$key[0]construct.Here’s one way to do it:
sub CreateKeyPath { my ($subtree, $path) = @_; # break it into components # strip initial path separator, if there is one $path =~ s#^\\##; my (@klist) = split(/\\/, $path); my $key; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access