Skip to content

Instantly share code, notes, and snippets.

@captn3m0
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captn3m0/7d095ea04020047169a0 to your computer and use it in GitHub Desktop.
Save captn3m0/7d095ea04020047169a0 to your computer and use it in GitHub Desktop.
Simple script to check if visitor is from IITR (Ruby)

Sample ruby code to check if the request IP is from a location in IIT-Roorkee.

  • Remember to install the netaddr gem.
  • IP ranges used from http://www.iitr.ac.in/radware/
  • If you are using cloudflare, install mod_cloudflare for apache
require 'netaddr'
def from_iitr?(ip)
# These are the 4 IP ranges that are alloted to iitr
# See http://www.iitr.ac.in/radware/
cidr_array = ["59.163.196.15/24",
"210.212.58.15/24",
"10.116.192.15/24",
"180.149.49.237/24"
]
cidr_array.each do |cidr|
cidr_obj = NetAddr::CIDR.create(cidr)
res = cidr_obj.matches?(ip)
return true if res
end
false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment