Skip to content

Instantly share code, notes, and snippets.

@zorteran
Created December 14, 2021 18:04
Show Gist options
  • Save zorteran/ebb30068ae5a40aa1ad47c78ed8c7209 to your computer and use it in GitHub Desktop.
Save zorteran/ebb30068ae5a40aa1ad47c78ed8c7209 to your computer and use it in GitHub Desktop.
require 'csv'
require 'ipaddr'
table = CSV.read("/home/maciej/ipv4.txt")
ips = table.map { |row| IPAddr.new(row[0]) }
ip_to_check = IPAddr.new("1.96.1.1")
result = ips.reduce(0) { |sum, ip| sum + (ip.include?(ip_to_check) ? 1 : 0)}
@zorteran
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment