Sample ruby code to check if the request IP is from a location in IIT-Roorkee.
- Remember to install the
netaddrgem. - IP ranges used from http://www.iitr.ac.in/radware/
- If you are using cloudflare, install mod_cloudflare for apache
Sample ruby code to check if the request IP is from a location in IIT-Roorkee.
netaddr gem.| 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 |