Created
August 18, 2012 21:23
-
-
Save gaffneyc/3389969 to your computer and use it in GitHub Desktop.
Simple ruby class for loading a list of unprovisioned IPv4 addresses and testing if an IP is in that range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ipaddr" | |
require "net/http" | |
# Q: What is a bogon? | |
# A: See http://www.team-cymru.org/Services/Bogons/ | |
class BogonList | |
LIST_URL = "http://www.team-cymru.org/Services/Bogons/fullbogons-ipv4.txt" | |
def self.addresses | |
@addresses ||= self.load | |
end | |
def self.load | |
bogons = [] | |
Net::HTTP.get(URI.parse(LIST_URL)).each_line do |line| | |
if line !~ /^#/ | |
bogons << IPAddr.new(line.chomp) | |
end | |
end | |
@addresses = bogons | |
end | |
def self.include?(addr) | |
addr = IPAddr.new(addr) | |
BogonList.addresses.any? { |range| range.include?(addr) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment