40 lines
700 B
Ruby
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)
|