class Ipify
Detects your current IP via `ifconfig`
Public Class Methods
new(network_interface, version)
click to toggle source
# 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
Public Instance Methods
detect()
click to toggle source
# File lib/detectors/ipify.rb, line 12 def detect command = [ 'curl', "-#{@version}", "--interface #{@network_interface}", "'https://api.ipify.org?format=text'", '-s' ].join(' ') ip = `#{command}` raise 'no ip detected' unless ip ip end