check-cidr-list/2.rb
Eliezer Croitoru 3933cf6cb7 1
2024-09-24 09:10:26 +03:00

40 lines
700 B
Ruby

#!/usr/bin/env ruby
require 'net/http'
require 'netaddr'
def validate_cidr?(cidr)
begin
IPAddr.new(cidr)
return true
rescue IPAddr::InvalidAddressError
return false
end
end
def process_url(url)
begin
uri = URI(url)
response = Net::HTTP.get(uri)
rescue URI::InvalidURIError, Net::HTTPError => e
puts "Error fetching URL: #{e.message}"
return
end
cidrs = response.split("\n")
cidrs.each do |cidr|
if validate_cidr?(cidr)
puts "Valid CIDR: #{cidr}"
else
puts "Invalid CIDR: #{cidr}"
end
end
end
# Get the URL from the user
puts "Enter the URL containing the IPv4 CIDR list:"
url = gets.chomp
# Process the URL
process_url(url)