Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Pulling IPv6 Address from Hostname

by gokuraku (Monk)
on Mar 20, 2008 at 11:54 UTC ( [id://675201]=note: print w/replies, xml ) Need Help??


in reply to Re: Pulling IPv6 Address from Hostname
in thread Pulling IPv6 Address from Hostname

Because what I wanted to do was dynamically get the localhost, this is for scripts that will run on multiple machines, and then use that to get the IPv6 address I came up with the following. I put the print statements in just so I can check that I have things following the right paths for various machines, and right now once I get the address the script exits. After I test it on a sampling of machines I will update this to just send the IP address back, the regular expression still needs work, but I haven't found a good way to pull IPv6 formatted addresses yet. When I do, I'll update this.
sub getHostIPv6() { my $hostName = Net::Domain::hostfqdn(); my $ip; my @rawIpData; print "Found $hostName\n"; if ($^O =~ m/Win/) { print "Running $^O - Win\n"; @rawIpData = `nslookup -q=AAAA $hostName`; } elsif ($^O =~ m/solaris/) { print "Running $^O - Solaris\n"; @rawIpData = `ifconfig -a`; } else { print "Running $^O - Unix\n"; # Pull out the matching ip @rawIpData = `host -avt AAAA $hostName`; } foreach my $line (@rawIpData) { if ($line =~ m/AAAA/ && $line =~ m/IPv6/) { $line =~ s/^.*IPv6\saddress\s=\s//; chomp($line); # Return IPv6 IP $ip = $line; } elsif ($line =~ m/inet6/) { $line =~ s/^\s+inet6\s+//; chomp($line); # Return IPv6 IP $ip = $line; } } if ($ip eq "") { print "Did not find an IPv6 address on the $^O machine\n"; exit(1); } print "Found IP-$ip.\n"; exit(1); }

Replies are listed 'Best First'.
Re^3: Pulling IPv6 Address from Hostname
by Khen1950fx (Canon) on Mar 21, 2008 at 21:21 UTC
    For host, try:

    host -it AAAA pnrpv2.ipv6.microsoft.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://675201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found