added ipv4 cidr and addresses filter

This commit is contained in:
Eliezer Croitoru 2024-04-09 01:24:28 +03:00
parent c9ab01c132
commit a9bfdc9e23

View File

@ -1,6 +1,7 @@
#!/usr/bin/env ruby
#require 'spf/query'
require 'ipaddr'
domain = ARGV[0]
@ -173,7 +174,30 @@ def getAllSpfIp4(domain)
base_dom["ipv4"].each { |cidr| ipv4 << cidr }
return ipv4
# filter ipv4 list
new_ipv4 = []
ipv4.each do |ip|
if valid_cidr?(ip) or valid_ip_address?(ip)
new_ipv4 << ip
end
end
return new_ipv4
end
def valid_cidr?(input)
IPAddr.new(input)
true
rescue IPAddr::InvalidAddressError
false
end
def valid_ip_address?(input)
IPAddr.new(input)
true
rescue IPAddr::InvalidAddressError
false
end
puts getAllSpfIp4(domain)