Skip to content

Instantly share code, notes, and snippets.

@gaffneyc
Created August 18, 2012 21:23
Show Gist options
  • Save gaffneyc/3389969 to your computer and use it in GitHub Desktop.
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
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