Class: Dumper::Utility::IP

Inherits:
Object
  • Object
show all
Defined in:
lib/dumper/utility.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ IP

Returns a new instance of IP.



9
10
11
12
13
14
15
16
17
# File 'lib/dumper/utility.rb', line 9

def initialize(*args)
  disable_reverse_lookup do
    UDPSocket.open do |s|
      s.connect '64.233.187.99', 1
      @ip = s.addr.last
    end
  end
  @ipaddr = Dumper::Utility::IPAddr.new(@ip)
end

Instance Attribute Details

#ipObject (readonly)

Returns the value of attribute ip.



7
8
9
# File 'lib/dumper/utility.rb', line 7

def ip
  @ip
end

#ipaddrObject (readonly)

Returns the value of attribute ipaddr.



7
8
9
# File 'lib/dumper/utility.rb', line 7

def ipaddr
  @ipaddr
end

Instance Method Details

#disable_reverse_lookupObject



19
20
21
22
23
24
25
26
27
# File 'lib/dumper/utility.rb', line 19

def disable_reverse_lookup
  orig = Socket.do_not_reverse_lookup
  Socket.do_not_reverse_lookup = true
  begin
    yield
  ensure
    Socket.do_not_reverse_lookup = orig
  end
end