module RknIpLookup::Checker

Public Class Methods

check(host_or_ip) click to toggle source
# File lib/rkn_ip_lookup/checker.rb, line 4
def check(host_or_ip)
  if host_or_ip.match?(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)
    check_ip(host_or_ip)
  else
    check_host(host_or_ip)
  end
end
check_host(host) click to toggle source
# File lib/rkn_ip_lookup/checker.rb, line 16
def check_host(host)
  ip = IPSocket.getaddress(host)
  check_ip(ip)
rescue SocketError
  false
end
check_ip(ip) click to toggle source
# File lib/rkn_ip_lookup/checker.rb, line 12
def check_ip(ip)
  db.ips.include?(ip) || db.cidrs.include?(ip) || false
end

Private Class Methods

db() click to toggle source
# File lib/rkn_ip_lookup/checker.rb, line 25
def db
  Database.load
end