Class: Enricher::Bogon
- Inherits:
-
Object
- Object
- Enricher::Bogon
- Defined in:
- lib/enricher/bogon.rb
Overview
Bogons ipv4 allow for both static simple checks and for dynamic full Bogon list checks provided by Team Cymru.
>> @@mybogon = Enricher::Bogon.new(:live)^C >> @@mybogon.contains?(‘205.166.22.1’)
> true
>> @@mybogon = Enricher::Bogon.new(:ipv4)
> #<Enricher::Bogon:0x00000002fb0368 @bogon=[0.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.0.0.0/24, 192.0.2.0/24, 192.168.0.0/16, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24, 224.0.0.0/4, 240.0.0.0/4]>
>> @@mybogon.contains?(‘205.166.22.1’)
> false
Constant Summary collapse
- BOGONIPV4 =
['0.0.0.0/8', '10.0.0.0/8', '100.64.0.0/10', '127.0.0.0/8', '169.254.0.0/16', '172.16.0.0/12', '192.0.0.0/24', '192.0.2.0/24', '192.168.0.0/16', '198.18.0.0/15', '198.51.100.0/24', '203.0.113.0/24', '224.0.0.0/4', '240.0.0.0/4']
- LIST_URL =
"http://www.team-cymru.org/Services/Bogons/fullbogons-ipv4.txt"
Instance Method Summary collapse
- #addresses ⇒ Object
- #contains?(ip) ⇒ Boolean
-
#initialize(bogon) ⇒ Bogon
constructor
A new instance of Bogon.
Constructor Details
#initialize(bogon) ⇒ Bogon
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/enricher/bogon.rb', line 32 def initialize(bogon) if bogon == :ipv4 @bogon = BOGONIPV4.collect do |cidr| NetAddr::CIDR.create(cidr) end elsif bogon == :live @bogon = [] Net::HTTP.get(URI.parse(LIST_URL)).each_line do |line| if line !~ /^#/ @bogon << NetAddr::CIDR.create(line.strip) end end else raise BogonSetUndefined, "Only the :ipv4 aggregated set, and :live via http is defined at this time. illegal use of #{bogon}" end @bogon end |
Instance Method Details
#addresses ⇒ Object
56 57 58 |
# File 'lib/enricher/bogon.rb', line 56 def addresses @bogon ||= self.initialize end |
#contains?(ip) ⇒ Boolean
51 52 53 54 |
# File 'lib/enricher/bogon.rb', line 51 def contains?(ip) @bogon.each { |net| return true if net.contains?(ip) } return false end |