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); }

In reply to Re^2: Pulling IPv6 Address from Hostname by gokuraku
in thread Pulling IPv6 Address from Hostname by gokuraku

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.