summaryrefslogtreecommitdiffstats
path: root/lib/facter/ipaddress6.rb
blob: 547d636a73ebceb835688c734523bbea2a990d20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Cody Herriges <c.a.herriges@gmail.com>
#
# Used the ipaddress fact that is already part of
# Facter as a template.

# OS dependant code that parses the output of various networking
# tools and currently not very intelligent. Returns the first
# non-loopback and non-linklocal address found in the ouput unless
# a default route can be mapped to a routeable interface. Guessing
# an interface is currently only possible with BSD type systems
# to many assumptions have to be made on other platforms to make
# this work with the current code. Most code ported or modeled
# after the ipaddress fact for the sake of similar functionality
# and familiar mechanics.
Facter.add(:ipaddress6) do
  confine :kernel => :linux
  setcode do
    ip = nil
    output = Facter::Util::Resolution.exec('/sbin/ifconfig')

    output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
      str = str.to_s
      unless str =~ /fe80.*/ or str == "::1"
        ip = str
      end
    }

    ip

  end
end

Facter.add(:ipaddress6) do
  confine :kernel => %w{SunOS}
  setcode do
    output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a')
    ip = nil

    output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
      str = str.to_s
      unless str =~ /fe80.*/ or str == "::1"
        ip = str
      end
    }

    ip

  end
end

Facter.add(:ipaddress6) do
  confine :kernel => %w{Darwin FreeBSD OpenBSD}
  setcode do
    output = Facter::Util::Resolution.exec('/sbin/ifconfig -a')
    ip = nil

    output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str|
      str = str.to_s
      unless str =~ /fe80.*/ or str == "::1"
        ip = str
        break
      end
    end

    ip
  end
end