diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-23 15:06:49 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-23 15:06:49 +0000 |
commit | 1531a4e34041d42600bea0904e209434e480952d (patch) | |
tree | 75f6ad82852960df378c8e0d6c0239aca29635b4 /lib/custodian/util/bytemark.rb | |
parent | 017e20155e9dc40e4a006df862804b3fbd1acefd (diff) |
Moved the code to detect whether an IP-address is inside/outside the Bytemark range into its own class & added _simple_ test-cases.
Diffstat (limited to 'lib/custodian/util/bytemark.rb')
-rw-r--r-- | lib/custodian/util/bytemark.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/custodian/util/bytemark.rb b/lib/custodian/util/bytemark.rb new file mode 100644 index 0000000..8143c4c --- /dev/null +++ b/lib/custodian/util/bytemark.rb @@ -0,0 +1,43 @@ + + +require 'ipaddr' + + + +# +# This class contains some Bytemark-specific tests/code. +# +module Custodian + + module Util + + class Bytemark + + + # + # The currently allocated IP-ranges which belong to Bytemark. + # + # These are used to test if an alert refers to a machine outwith our + # network. + # + BYTEMARK_RANGES = %w(80.68.80.0/20 89.16.160.0/19 212.110.160.0/19 46.43.0.0/18 91.223.58.0/24 213.138.96.0/19 5.153.224.0/21 2001:41c8::/32).collect{|i| IPAddr.new(i)} + + + # + # Is the named target inside the Bytemark IP-range? + # + def Bytemark.inside?( target ) + inside = false + + if ( BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(target))} ) + inside = true + end + + inside + end + + + + end + end +end |