Class: Pingfacts::PingerResult
- Inherits:
-
Object
- Object
- Pingfacts::PingerResult
- Defined in:
- lib/pingfacts.rb
Constant Summary collapse
- @@strictmode =
false
- @@vendors =
nil
Instance Attribute Summary collapse
-
#dnsname ⇒ Object
Returns the value of attribute dnsname.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#mac ⇒ Object
Returns the value of attribute mac.
Class Method Summary collapse
- .configs ⇒ Object
- .configs=(new_value) ⇒ Object
- .strictmode ⇒ Object
- .strictmode=(new_value) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#dnsname ⇒ Object
Returns the value of attribute dnsname.
20 21 22 |
# File 'lib/pingfacts.rb', line 20 def dnsname @dnsname end |
#ip ⇒ Object
Returns the value of attribute ip.
20 21 22 |
# File 'lib/pingfacts.rb', line 20 def ip @ip end |
#mac ⇒ Object
Returns the value of attribute mac.
20 21 22 |
# File 'lib/pingfacts.rb', line 20 def mac @mac end |
Class Method Details
.configs ⇒ Object
30 31 32 |
# File 'lib/pingfacts.rb', line 30 def self.configs @@configs end |
.configs=(new_value) ⇒ Object
34 35 36 |
# File 'lib/pingfacts.rb', line 34 def self.configs=(new_value) @@configs = new_value end |
.strictmode ⇒ Object
22 23 24 |
# File 'lib/pingfacts.rb', line 22 def self.strictmode @@strictmode end |
.strictmode=(new_value) ⇒ Object
26 27 28 |
# File 'lib/pingfacts.rb', line 26 def self.strictmode=(new_value) @@strictmode = new_value end |
Instance Method Details
#eql?(other) ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pingfacts.rb', line 76 def eql?(other) if @@strictmode return (self.ip == other.ip and self.mac == other.mac and self.dnsname == other.dnsname) end result = false if self.mac != nil and other.mac != nil if self.mac == other.mac result = true end end if self.dnsname != nil and other.dnsname != nil if self.dnsname == other.dnsname return true end end if self.ip != nil and other.ip != nil if self.ip == other.ip result = true end end return result end |
#path_vendorlist ⇒ Object
38 39 40 |
# File 'lib/pingfacts.rb', line 38 def path_vendorlist "#{@@configs}/vendorlist" end |
#prepare_configs ⇒ Object
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 69 70 71 72 73 74 |
# File 'lib/pingfacts.rb', line 42 def prepare_configs begin Dir.mkdir(@@configs) rescue Errno::EEXIST end vendor_content = nil unless File.exist? path_vendorlist vendor_content = URI.open("http://standards-oui.ieee.org/oui/oui.txt").read open(path_vendorlist, "w") do |file| file << vendor_content end else if @@vendors.nil? open(path_vendorlist, "r") do |file| vendor_content = file.read end end end if @@vendors.nil? and (not vendor_content.nil?) @@vendors = {} vendor_content.lines.each do |line| if (/\(base\s+16\)/i).match(line) result = (/^([0-9A-F]+)\s+\(base\s+16\)\s+(.+)$/i).match(line) unless result.nil? @@vendors[result[1]] = result[2] end end end end end |
#vendor ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pingfacts.rb', line 100 def vendor if self.mac.nil? return nil end self.prepare_configs teststring = self.mac.upcase.gsub /[^0-9A-F]*/i, "" result = @@vendors[teststring[0,6]] if result.nil? return nil end return result.strip end |