Class: Net::Dns::Rbl::Netcheck

Inherits:
Object
  • Object
show all
Defined in:
lib/net-dns-rbl/netcheck.rb

Instance Method Summary collapse

Constructor Details

#initialize(ip) ⇒ Netcheck

Returns a new instance of Netcheck.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/net-dns-rbl/netcheck.rb', line 9

def initialize(ip)
  raise ArgumentError, "Invalid IP specified" if !ip.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
  @reverseip = ip.split('.').reverse.join('.')
  @lists = LISTS
end

Instance Method Details

#addToLists(list) ⇒ Object

Add additional dnsbl lookup lists



16
17
18
# File 'lib/net-dns-rbl/netcheck.rb', line 16

def addToLists(list)
  @lists.push(list)
end

#performLookupsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/net-dns-rbl/netcheck.rb', line 29

def performLookups
  @lists.each do |l|
    begin
      host = @reverseip+'.'+l
      resip = Resolv::getaddress(host)
      if resip.match(/(127)\.\d{1}\.\d{1,3}\.\d{1,3}/)
        @listed << l
      end

    rescue Exception => e
      case e
      when Resolv::ResolvError
        nil
      when Interrupt
        puts "\nCaught signal SIGINT. Exiting..."
        exit 1
      else
        puts ": \e[0;47mTIMEOUT\e[0m\n"
      end
    end
  end
  return @listed
end

#removeFromLists(list) ⇒ Object

Remove an existing dnsbl list from the existing hash



21
22
23
# File 'lib/net-dns-rbl/netcheck.rb', line 21

def removeFromLists(list)
  @lists.delete(list)
end

#showCurrentListsObject



25
26
27
# File 'lib/net-dns-rbl/netcheck.rb', line 25

def showCurrentLists
  @lists
end