You can get the IP address of the client using the HttpRequest.UserHostAddress property (the instance can be accessed using this.Request from any page or using the static HttpContext.Current property).
As far as I know, there is no standard method that compares the IP address with the specified range, so you need to implement this bit yourself.
You will probably want to check this for every request that can be executed either in the OnInit method of each page (which you want to block) or in the BeginRequest application event (usually in Global.asax ).
If you find a blocked address, you can display a blank (fill-in) page using the Server.Transfer method ( Response.End will be another alternative, but it just shortens the page - returns a blank page, and Server.Transfer allows Server.Transfer to display some message to the client).
Tomas petricek
source share