Sha256: ad20fa3f1065051a12463bea47506393a82b886bcd78cf81417b84b0b11ce725

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'netaddr'
require 'string_ext'

module SSHScan
  class TargetParser
    def enumerateIPRange(ip, port = "22")
      if ip.fqdn?
        socket = ip.concat(":").concat(port.to_s)
        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)
          ip_array.map! { |ip| ip.concat(":").concat(port.to_s) }
          return ip_array
        elsif ip.include? "/"
          cidr = NetAddr::CIDR.create(ip)
          ip_array = cidr.enumerate
          ip_array.delete(cidr.network)
          ip_array.delete(cidr.last)
          ip_array.map! { |ip| ip.concat(":").concat(port.to_s) }
          return ip_array
        else
          socket = ip.concat(":").concat(port.to_s)
          return [socket]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ssh_scan-0.0.12 lib/ssh_scan/target_parser.rb
ssh_scan-0.0.12.beta.2 lib/ssh_scan/target_parser.rb
ssh_scan-0.0.12.beta.1 lib/ssh_scan/target_parser.rb
ssh_scan-0.0.11 lib/ssh_scan/target_parser.rb