Class: Ifconfig
- Inherits:
-
Object
- Object
- Ifconfig
- Defined in:
- lib/detectors/ifconfig.rb
Overview
Detects your current IP via ‘ifconfig`
Instance Method Summary collapse
- #detect ⇒ Object
-
#initialize(network_interface, _version) ⇒ Ifconfig
constructor
A new instance of Ifconfig.
Constructor Details
#initialize(network_interface, _version) ⇒ Ifconfig
Returns a new instance of Ifconfig.
5 6 7 |
# File 'lib/detectors/ifconfig.rb', line 5 def initialize(network_interface, _version) @network_interface = network_interface end |
Instance Method Details
#detect ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/detectors/ifconfig.rb', line 9 def detect command = [ "ifconfig #{@network_interface} inet6", 'grep inet6', 'grep -v fe80', 'grep -v deprecated' ].join(' | ') raw = `#{command}` ip = raw.lstrip.split(' ')[1] raise 'no ip detected' unless ip ip end |