Method: IPAdmin.arpa
- Defined in:
- lib/ip_admin.rb
.arpa(object) ⇒ Object
Using the provided IPAdmin::CIDR object, return either an in-addr.arpa. or ip6.arpa. string. The netmask will be used to determine the length of the returned arpa string.
-
Arguments:
-
IPAdmin::CIDR object
-
-
Returns:
-
IP address in in-addr.arpa or ip6.arpa format
-
Note:
IPAdmin.arpa will use the original IP address passed during the initialization
of the CIDR objects. This IP can be found using the CIDR.ip() method.
Example:
arpa = IPAdmin.arpa(cidr)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ip_admin.rb', line 30 def arpa(object) unless (object.kind_of? IPAdmin::CIDR) raise ArgumentError, "Expected IPAdmin::CIDR object, " + "but #{object.class} provided." end base = object.ip() netmask = object.bits() if (object.version == 4) net = base.split('.') if (netmask) while (netmask < 32) net.pop netmask = netmask + 8 end end arpa = net.reverse.join('.') arpa << ".in-addr.arpa." elsif (object.version == 6) fields = base.split(':') net = [] fields.each do |field| (field.split("")).each do |x| net.push(x) end end if (netmask) while (netmask < 128) net.pop netmask = netmask + 4 end end arpa = net.reverse.join('.') arpa << ".ip6.arpa." end return(arpa) end |