hummingbird-me/kitsu-server

View on GitHub
bin/util/format_geolite2_ipasn_csv

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'csv'
require 'ipaddr'

ARGV.each do |file|
  CSV.open(file, 'r', headers: true).each do |row|
    network = IPAddr.new(row['network']).to_range
    puts CSV.generate_line([
      network.begin,
      network.end,
      row['autonomous_system_number'],
      row['autonomous_system_organization']
    ])
  end
end