Sha256: 16b7d6100b88eb780792490abc9405c874a7b301332cbca4816fbb1caeb8a4ee
Contents?: true
Size: 1.54 KB
Versions: 21
Compression:
Stored size: 1.54 KB
Contents
require 'netaddr' require 'string_ext' module SSHScan # Enumeration methods for IP notations. class TargetParser # Enumerate CIDR addresses, single IPs and IP ranges. # @param ip [String] IP address # @param port [Fixnum] port # @return [Array] array of enumerated addresses def enumerateIPRange(ip,port) if ip.fqdn? if port.nil? socket = ip else socket = ip.concat(":").concat(port.to_s) end return [socket] else if ip.include? "-" octets = ip.split('.') range = octets.pop.split('-') lower = NetAddr::CIDR.create(octets.join('.') + "." + range[0]) upper = NetAddr::CIDR.create(octets.join('.') + "." + range[1]) ip_array = NetAddr.range(lower, upper,:Inclusive => true) if !port.nil? ip_array.map! { |i| i.concat(":").concat(port.to_s) } end return ip_array elsif ip.include? "/" begin cidr = NetAddr::CIDR.create(ip) rescue raise ArgumentError, "Invalid target: #{ip}" end ip_array = cidr.enumerate ip_array.delete(cidr.network) ip_array.delete(cidr.last) if !port.nil? ip_array.map! { |i| i.concat(":").concat(port.to_s) } end return ip_array else if port.nil? socket = ip else socket = ip.concat(":").concat(port.to_s) end return [socket] end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems