Restrict based on IP address

  • Thread starter richard.mcgrath
  • Start date
R

richard.mcgrath

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
 
L

Lau Lei Cheong

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...
 
J

Juan T. Llibre

Download and use Softperfect's free network scanner :

http://www.softperfect.com/products/networkscanner/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.
 
L

Lau Lei Cheong

Oh ban by Left()... Then it'll left tiny holes if the netmasks are
128/64/32/16 ones.. :p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top