Class: Ipify
- Inherits:
-
Object
- Object
- Ipify
- Defined in:
- lib/detectors/ipify.rb
Overview
Detects your current IP via ‘ifconfig`
Instance Method Summary collapse
- #detect ⇒ Object
-
#initialize(network_interface, version) ⇒ Ipify
constructor
A new instance of Ipify.
Constructor Details
#initialize(network_interface, version) ⇒ Ipify
Returns a new instance of Ipify.
5 6 7 8 9 10 |
# File 'lib/detectors/ipify.rb', line 5 def initialize(network_interface, version) @network_interface = network_interface @version = version == 6 ? 6 : 4 raise 'Ipify supports only IPv4 yet' if version == 6 end |
Instance Method Details
#detect ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/detectors/ipify.rb', line 12 def detect ip = `curl -#{@version} --interface #{@network_interface} 'https://api.ipify.org?format=text' -s` raise 'no ip detected' unless ip ip end |