class Scriptroute::IPaddress
Public Class Methods
new(n)
click to toggle source
@param n [String,IPaddress,Integer] a hostname, an IP
address in string form, another IPaddress
or an IP
address in numeric form
# File lib/scriptroute/packets.rb, line 221 def initialize(n) raise "Seems bad to initialize an IPaddress with nil." unless n if(n.is_a?(String)) then shf = 32 if n =~ /^[\d\.]+$/ then @addr = n.split('.').map { |i| shf -= 8; i.to_i << shf }.sum else addr = Scriptroute::dns_lookup(n) if addr then @addr = addr.split('.').map { |i| shf -= 8; i.to_i << shf }.sum else $stderr.puts "unable to lookup #{n}" @addr = 0 end end elsif(n.is_a?(IPaddress)) then @addr = n.to_i else @addr = n end end
Public Instance Methods
<=>(other)
click to toggle source
Compares numerically, for sorting.
# File lib/scriptroute/packets.rb, line 264 def <=>(other) @addr <=> other.to_i end
==(other)
click to toggle source
Compares numerically, for equality test.
# File lib/scriptroute/packets.rb, line 268 def ==(other) @addr == other.to_i end
eql?(other)
click to toggle source
in case you would like to store a {Hash} with IPaddresses as keys
# File lib/scriptroute/packets.rb, line 260 def eql?(other) @addr == other.to_i end
hash()
click to toggle source
in case you would like to store a {Hash} with IPaddresses as keys
# File lib/scriptroute/packets.rb, line 256 def hash @addr end
inspect()
click to toggle source
just invokes to_s
for now. @return [String]
# File lib/scriptroute/packets.rb, line 248 def inspect to_s end
nameify()
click to toggle source
@returns [String] using {Scriptroute::nameify}
# File lib/scriptroute/packets.rb, line 272 def nameify Scriptroute.nameify(self.to_s) end
to_i()
click to toggle source
@return [Integer]
# File lib/scriptroute/packets.rb, line 252 def to_i @addr end
to_s()
click to toggle source
@return [String] dotted quad notation of the IP
address.
# File lib/scriptroute/packets.rb, line 243 def to_s [ @addr >> 24, @addr >> 16, @addr >> 8, @addr ].map { |i| i & 0xff }.join(".") end