473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Restrict based on IP address

Hi,

I have to restrict access to a site based on IP address. While I have
been able to this successfully with code in the Global.aspx file, some
if the IP address are not single IP addresses but rather ranges.

If I know the network ID and the subnet mask, how can I check if a
given IP address falls within that range?

Thanks for any help,
Richard

Nov 19 '05 #1
4 2035
You perform AND with the netmask to the IP you want to check, then compare
the result with the network IP of the netmask, if they're the same, then the
IP you want to check falls in range, otherwise, proceed to next network IP +
netmask pair...

<ri*************@gmail.com>
???????:11**********************@f14g2000cwb.googl egroups.com...
Hi,

I have to restrict access to a site based on IP address. While I have
been able to this successfully with code in the Global.aspx file, some
if the IP address are not single IP addresses but rather ranges.

If I know the network ID and the subnet mask, how can I check if a
given IP address falls within that range?

Thanks for any help,
Richard

Nov 19 '05 #2
Download and use Softperfect's free network scanner :

http://www.softperfect.com/products/...canner/manual/

It will help you understand these concepts a lot
easier than working on a theoretical basis.

In particular , check the "Options" - "Auto detect Local IP range" menu.

Download it at : http://www.softperfect.com/download/

OTOH, you *can* ban by IP range in global.asax,
if you use the Left function in VB.NET.

i.e., if you are interested in banning IPs from 192.168.0.0 to 198.168.0.255

you'd check the UserHostAddress and use the Left function
to determine whether the leftmost 9 characters are 192.168.0.

That would identify the 256 IP addtesses from 192.168.0.0 to 198.168.0.255

The same principle applies to any IP range.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
<ri*************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I have to restrict access to a site based on IP address. While I have
been able to this successfully with code in the Global.aspx file, some
if the IP address are not single IP addresses but rather ranges.

If I know the network ID and the subnet mask, how can I check if a
given IP address falls within that range?

Thanks for any help,
Richard

Nov 19 '05 #3
Oh ban by Left()... Then it'll left tiny holes if the netmasks are
128/64/32/16 ones.. :P

"Juan T. Llibre" <no***********@nowhere.com> ¼¶¼g©ó¶l¥ó·s»D:e0**************@TK2MSFTNGP14.phx.g bl...
Download and use Softperfect's free network scanner :

http://www.softperfect.com/products/...canner/manual/

It will help you understand these concepts a lot
easier than working on a theoretical basis.

In particular , check the "Options" - "Auto detect Local IP range" menu.

Download it at : http://www.softperfect.com/download/

OTOH, you *can* ban by IP range in global.asax,
if you use the Left function in VB.NET.

i.e., if you are interested in banning IPs from 192.168.0.0 to
198.168.0.255

you'd check the UserHostAddress and use the Left function
to determine whether the leftmost 9 characters are 192.168.0.

That would identify the 256 IP addtesses from 192.168.0.0 to 198.168.0.255

The same principle applies to any IP range.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
<ri*************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I have to restrict access to a site based on IP address. While I have
been able to this successfully with code in the Global.aspx file, some
if the IP address are not single IP addresses but rather ranges.

If I know the network ID and the subnet mask, how can I check if a
given IP address falls within that range?

Thanks for any help,
Richard


Nov 19 '05 #4
Well, that *was* an alternate choice, not a primary recommendation.

;-)

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:um*************@TK2MSFTNGP14.phx.gbl...
Oh ban by Left()... Then it'll left tiny holes if the netmasks are 128/64/32/16 ones..
:P

"Juan T. Llibre" <no***********@nowhere.com>
¼¶¼g©ó¶l¥ó·s»D:e0**************@TK2MSFTNGP14.phx.g bl...
Download and use Softperfect's free network scanner :

http://www.softperfect.com/products/...canner/manual/

It will help you understand these concepts a lot
easier than working on a theoretical basis.

In particular , check the "Options" - "Auto detect Local IP range" menu.

Download it at : http://www.softperfect.com/download/

OTOH, you *can* ban by IP range in global.asax,
if you use the Left function in VB.NET.

i.e., if you are interested in banning IPs from 192.168.0.0 to 198.168.0.255

you'd check the UserHostAddress and use the Left function
to determine whether the leftmost 9 characters are 192.168.0.

That would identify the 256 IP addtesses from 192.168.0.0 to 198.168.0.255

The same principle applies to any IP range.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
<ri*************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I have to restrict access to a site based on IP address. While I have
been able to this successfully with code in the Global.aspx file, some
if the IP address are not single IP addresses but rather ranges.

If I know the network ID and the subnet mask, how can I check if a
given IP address falls within that range?

Thanks for any help,
Richard



Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: gc | last post by:
Hi, What is the purpose of the restrict keyword? gc
7
by: tweak | last post by:
Can someone give me a short example as how to best use this keyword in your code? This is my understanding: by definition restrict sounds like it is suppose to restrict access to memory...
1
by: ccdrbrg | last post by:
I'm having trouble understanding restrict. Can someone provide a layman's explanation. Chad
2
by: pemo | last post by:
In Harbison and Steele's book, they say that using 'restrict' allows functions like memcpy() to be prototyped like this: void * memcpy(void * restrict s1, const void * restrict s2, size_t n); ...
11
by: pemo | last post by:
If you were to compile/run the code below, and get the result '30', I'd be very interested to know what compiler you're using - and its optimisation settings #include <stdio.h> int test(int...
12
by: Me | last post by:
I'm trying to wrap my head around the wording but from what I think the standard says: 1. it's impossible to swap a restrict pointer with another pointer, i.e. int a = 1, b = 2; int *...
21
by: Niu Xiao | last post by:
I see a lot of use in function declarations, such as size_t fread(void* restrict ptr, size_t size, size_t nobj, FILE* restrict fp); but what does the keyword 'restrict' mean? there is no...
2
by: Frederick Gotham | last post by:
I'm going to be using an acronym a lot in this post: IINM = If I'm not mistaken Let's say we've got translation units which are going to be compiled to object files, and that these object...
6
by: rainy6144 | last post by:
Does the following code have defined behavior? double *new_array(unsigned n) { double *p = malloc(n * sizeof(double)); unsigned i; for (i = 0; i < n; i++) p = 0.0; return p; }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.