Class: Socket

Inherits:
Object show all
Defined in:
lib/vex/base/net/socket_ext.rb

Overview

Defined Under Namespace

Modules: Etest

Class Method Summary collapse

Class Method Details

.local_ip(when_talking_to = nil) ⇒ Object

do_raise is mainly for test purposes



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vex/base/net/socket_ext.rb', line 14

def self.local_ip(when_talking_to = nil)
  when_talking_to ||= '64.233.187.99'
  begin
    orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  # turn off reverse DNS resolution temporarily  

    UDPSocket.open do |s|  
      s.connect when_talking_to, 1  
      s.addr.last  
    end  
  rescue
    "127.0.0.1" # not connected to the funny wide web?
  ensure  
    Socket.do_not_reverse_lookup = orig  
  end
end

.online?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/vex/base/net/socket_ext.rb', line 30

def self.online?
  local_ip != "127.0.0.1"
end