lib/tasks/helpers/whois.rb
def _whois_query_ripe_ip(lookup_string,out={})
    ripe_uri = "https://stat.ripe.net/data/address-space-hierarchy/data.json?resource=#{lookup_string}/32"
    json = JSON.parse(http_get_body(ripe_uri))

    data = json["data"]
    if data["last_updated"]
      range = data["last_updated"].first["ip_space"]
    else
      _log_error "Bad response, unable to continue: #{json}"
      return nil
    end

    # parse out description
    begin
      less_specific_hash = data["less_specific"]
      if less_specific_hash && less_specific_hash.first["descr"]
        _log "less_specific_hash: #{less_specific_hash}"
        description = less_specific_hash.first["descr"]
      end

      # parse out netname
      if less_specific_hash && less_specific_hash.first["netname"]
        netname = less_specific_hash.first["netname"]
      end

      out = out.merge({
        "name" => "#{range}",
        "start_address" => "#{range.split("/").first}",
        "cidr" => "#{range.split('/').last}",
        "description" => "#{description}".force_encoding('ISO-8859-1').sanitize_unicode,
        "rir" => "RIPE",
        "rir_parsed" => "#{json["data"]["rir"]}",
        "organization_reference" => "#{netname}".sanitize_unicode,
        "organization_name" => "#{description}".sanitize_unicode,
        "provider" =>  "#{description}".force_encoding('ISO-8859-1').sanitize_unicode })

    rescue TypeError => e
      _log_error "PARSING ERROR! Unable to get details from #{less_specific_hash} #{e}"
    end

  out
  end
# returns a hash that can create a netblock
returns a hash that can create a netblock
returns a hash that can create a netblock
def _whois_query_ripe_ip(lookup_string,out={})
    ripe_uri = "https://stat.ripe.net/data/address-space-hierarchy/data.json?resource=#{lookup_string}/32"
    json = JSON.parse(http_get_body(ripe_uri))
    data = json["data"]
    if data["last_updated"]
      range = data["last_updated"].first["ip_space"]
    else
      _log_error "Bad response, unable to continue: #{json}"
      return nil
    end
    begin
      less_specific_hash = data["less_specific"]
      if less_specific_hash && less_specific_hash.first["descr"]
        _log "less_specific_hash: #{less_specific_hash}"
        description = less_specific_hash.first["descr"]
      end
      if less_specific_hash && less_specific_hash.first["netname"]
        netname = less_specific_hash.first["netname"]
      end
      out = out.merge({
        "name" => "#{range}",
        "start_address" => "#{range.split("/").first}",
        "cidr" => "#{range.split('/').last}",
        "description" => "#{description}".force_encoding('ISO-8859-1').sanitize_unicode,
        "rir" => "RIPE",
        "rir_parsed" => "#{json["data"]["rir"]}",
        "organization_reference" => "#{netname}".sanitize_unicode,
        "organization_name" => "#{description}".sanitize_unicode,
        "provider" =>  "#{description}".force_encoding('ISO-8859-1').sanitize_unicode })
    rescue TypeError => e
      _log_error "PARSING ERROR! Unable to get details from #{less_specific_hash} #{e}"
    end
  out
  end
def _whois_query_ripe_ip ( lookup_string , out = { } ) ripe_uri = "https://stat.ripe.net/data/address-space-hierarchy/data.json?resource=#{lookup_string}/32" json = JSON . parse ( http_get_body ( ripe_uri ) ) data = json [ "data" ] if data [ "last_updated" ] range = data [ "last_updated" ] . first [ "ip_space" ] else _log_error "Bad response, unable to continue: #{json}" return nil end begin less_specific_hash = data [ "less_specific" ] if less_specific_hash && less_specific_hash . first [ "descr" ] _log "less_specific_hash: #{less_specific_hash}" description = less_specific_hash . first [ "descr" ] end if less_specific_hash && less_specific_hash . first [ "netname" ] netname = less_specific_hash . first [ "netname" ] end out = out . merge ( { "name" => "#{range}" , "start_address" => "#{range.split("/").first}" , "cidr" => "#{range.split('/').last}" , "description" => "#{description}" . force_encoding ( 'ISO-8859-1' ) . sanitize_unicode , "rir" => "RIPE" , "rir_parsed" => "#{json["data"]["rir"]}" , "organization_reference" => "#{netname}" . sanitize_unicode , "organization_name" => "#{description}" . sanitize_unicode , "provider" => "#{description}" . force_encoding ( 'ISO-8859-1' ) . sanitize_unicode } ) rescue TypeError => e _log_error "PARSING ERROR! Unable to get details from #{less_specific_hash} #{e}" end out end
returns a hash that can create a netblock
returns a hash that can create a netblock
# parse out description # parse out netname
lookup_string
out