MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 18.219.247.127
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/ruby/vendor_ruby/facter/util/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/ruby/vendor_ruby/facter/util/netmask.rb
module Facter::NetMask
  def self.get_netmask
    netmask = nil;
    ipregex = %r{(\d{1,3}\.){3}\d{1,3}}

    ops = nil
    case Facter.value(:kernel)
    when 'Linux'
      ops = {
        :ifconfig_opts => ['2>/dev/null'],
        :regex => %r{#{Facter.value(:ipaddress)}.*?(?:Mask:|netmask)\s*(#{ipregex})}x,
        :munge => nil,
      }
    when 'SunOS'
      ops = {
        :ifconfig_opts => ['-a'],
        :regex => %r{\s+ inet \s #{Facter.value(:ipaddress)} \s netmask \s (\w{8})}x,
        :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
      }
    when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly', 'AIX'
      ops = {
        :ifconfig_opts => ['-a'],
        :regex => %r{\s+ inet \s #{Facter.value(:ipaddress)} \s netmask \s 0x(\w{8})}x,
        :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
      }
    end

    String(Facter::Util::IP.exec_ifconfig(ops[:ifconfig_opts])).split(/\n/).collect do |line|
      matches = line.match(ops[:regex])
      if !matches.nil?
        if ops[:munge].nil?
          netmask = matches[1]
        else
          netmask = ops[:munge].call(matches[1])
        end
      end
    end
    netmask
  end
end

MMCT - 2023