module Myips

Constants

VERSION

Public Class Methods

local_ip() click to toggle source
# File lib/myips.rb, line 6
def local_ip
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  # turn off reverse DNS resolution temporarily

  UDPSocket.open do |s|
    s.connect '13.107.21.200', 1 # Using Bing.com ip
    s.addr.last
  end
ensure
  Socket.do_not_reverse_lookup = orig
end
public_ip() click to toggle source
# File lib/myips.rb, line 17
def public_ip
  require "net/http"
  ip = Net::HTTP.get(URI("https://api.ipify.org"))
end