Class: Cymru::IPAddress

Inherits:
Object
  • Object
show all
Includes:
DNSquery
Defined in:
lib/cymruwhois.rb

Constant Summary collapse

ORIGIN =
"origin.asn.cymru.com"
ORIGIN6 =
"origin6.asn.cymru.com"
BOGON =
"bogons.cymru.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DNSquery

#intxt

Constructor Details

#initializeIPAddress

Returns a new instance of IPAddress.



35
36
# File 'lib/cymruwhois.rb', line 35

def initialize
end

Instance Attribute Details

#allocdateObject (readonly)

Returns the value of attribute allocdate.



29
30
31
# File 'lib/cymruwhois.rb', line 29

def allocdate
  @allocdate
end

#asnameObject (readonly)

Returns the value of attribute asname.



29
30
31
# File 'lib/cymruwhois.rb', line 29

def asname
  @asname
end

#asnumObject (readonly)

Returns the value of attribute asnum.



29
30
31
# File 'lib/cymruwhois.rb', line 29

def asnum
  @asnum
end

#cidrObject (readonly)

Returns the value of attribute cidr.



29
30
31
# File 'lib/cymruwhois.rb', line 29

def cidr
  @cidr
end

#countryObject (readonly)

Returns the value of attribute country.



29
30
31
# File 'lib/cymruwhois.rb', line 29

def country
  @country
end

#registryObject (readonly)

Returns the value of attribute registry.



29
30
31
# File 'lib/cymruwhois.rb', line 29

def registry
  @registry
end

Instance Method Details

#whois(addr) ⇒ Object Also known as: lookup



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cymruwhois.rb', line 38

def whois(addr)
  ip = IPAddr.new(addr)
  if ip.ipv4?
    revdns = ip.reverse.sub("in-addr.arpa", ORIGIN)
  elsif ip.ipv6?
    revdns = ip.reverse.sub("ip6.arpa", ORIGIN6)
  end
  
  ansip = intxt(revdns)
  @asnum = ansip[0]
  @cidr = ansip[1]
  @country = ansip[2]
  @registry = ansip[3]
  @allocdate = ansip[4]

  # to address the multi ASN issue for the same IP Block 
  asparam = ansip[0].split
 
  ansasnum = Cymru::ASNumber.new
  ansasnum.whois(asparam[0])
  @asname = ansasnum.asname
  
  ansip << @asname
end