Skip to content

Instantly share code, notes, and snippets.

@davidjrice
Created March 8, 2010 22:25
Show Gist options
  • Select an option

  • Save davidjrice/325858 to your computer and use it in GitHub Desktop.

Select an option

Save davidjrice/325858 to your computer and use it in GitHub Desktop.
# IP Ranges of Litmus App servers
# http://litmusapp.com
#
# 67.202.0.0/18
# 72.44.32.0/19
# 75.101.128.0/17
# 174.129.0.0/16
# 184.73.0.0/16
# 184.72.0.0/18
# 204.236.192.0/18
# 204.236.128.0/18
# 204.9.221.14/32
# 209.20.0.0/16
# 216.182.224.0/20
class LitmusAppIp
# FOR GA 255 char limit!
#
# Caveats, due to tactics to shorten the regex for Google Analytics the
# following IP addresses should not be matched by this regex but will be.
# (I deemed it okay as they are most likely within the same hosting company)
#
# 67.202.0.19
# 184.73.0.17
# 184.73.0.18
# 184.73.0.19
# 184.72.0.19
# 204.236.192.19
# 204.236.128.19
#
# Perhaps it will work to write an include rule that will include them back in.
# ... though that kindof makes shortening it a bit of yak shaving.
#
SHORTENED_REGEX = /^(67\.202\.0\.(\d|1\d))|(72\.44\.32\.(\d|1\d))|(75\.101\.128\.(\d|1[0-7]))|(174\.129\.0\.(\d|1[0-6]))|(184\.(72|73)\.0\.(\d|1[0-8]))|(204\.236\.(192|128)\.(\d|1\d))|(204\.9\.221\.(1[4-9]|2\d|3[0-2]))|(209\.20\.0\.(\d|1[0-6]))|(216\.182\.224\.(\d|1\d|20))$/
# This is a perfect regex rule with no caveats.
# Thought it will need split up as two google analytics exclude filters
#
LONG_REGEX = /^(216\.182\.224\.([0-9]|1[0-9]|20))|(72\.44\.32\.([0-9]|1[0-9]))|(67\.202\.0\.([0-9]|1[0-8]))|(75\.101\.128\.([0-9]|1[0-7]))|(174\.129\.0\.([0-9]|1[0-6]))|(204\.236\.192\.([0-9]|1[0-8]))|(184\.73\.0\.([0-9]|1[0-6]))|(204\.236\.128\.([0-9]|1[0-8]))|(184\.72\.0\.([0-9]|1[0-8]))|(209\.20\.0\.([0-9]|1[0-6]))|(204\.9\.221\.(1[4-9]|2[0-9]|3[0-2]))$/
def self.match(address)
address =~ SHORTENED_REGEX
end
end
describe LitmusAppIp do
before(:all) do
@valid_ips = [ "216.182.224.0", "216.182.224.10", "216.182.224.20",
"72.44.32.0", "67.202.0.0",
"75.101.128.0", "174.129.0.0", "204.236.192.18", "184.73.0.1",
"204.236.128.5", "184.72.0.2", "209.20.0.3", "204.9.221.14"
]
@invalid_ips = [ "216.182.225.0", "72.44.52.0", "67.202.1.0",
"76.101.128.0", "194.129.0.0", "202.236.192.18", "183.73.0.1",
"234.236.128.5", "174.72.0.2", "201.20.0.3", "204.9.224.14", "216.182.224.21", "216.182.224.215"
]
end
it "should match litmus IP addresses" do
@valid_ips.each do |address|
LitmusAppIp.match(address).should == 0
end
end
it "should not match non litmus IP addresses" do
@invalid_ips.each do |address|
LitmusAppIp.match(address).should == nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment