473,385 Members | 2,044 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.

Excluding IP-ranges

Hi there,

I really need some input of how to approach my little assignment.

A customer wants to exclude all US IP-ranges from accessing part of
his website. From http://www.ipaddresslocation.org/ I've collected
about 16,000 ranges in the format

208.202.120.0 208.203.111.255
208.203.114.0 208.203.244.127
....

I don't yet know how many individual IP's then ranges totals, but I
reckon we speak millions.

Now, when a user hits that certain webpage a lookup should be
performed, checking if user is in a range. If he is, he's banned from
that part of the page.

My idea is to save to a table (MSSQL) that contains 4 columns - one
column for each part of the IP. When I import the ranges I save each
IP in that interval, ending up with all (or so) current US IP-
addresses. Each of the four columns are indexed.

A lookup will then use a phonebook-kinda-lookup (SELECT COUNT(*) FROM
myTable WHERE col1=62 AND col2=63 AND col3=64 and col4=65). If it
returns 0, user is allowed.

Is that a crappy approach, or should I consider something else?
Thanks in advance for any input.

Regards /Snedker
Jul 30 '08 #1
3 1507
Hi there,
>
I really need some input of how to approach my little assignment.

A customer wants to exclude all US IP-ranges from accessing part of

I don't yet know how many individual IP's then ranges totals, but I
reckon we speak millions.

Check with www.apnic.net


Jul 30 '08 #2
Snedker wrote:
Hi there,

I really need some input of how to approach my little assignment.

A customer wants to exclude all US IP-ranges from accessing part of
his website. From http://www.ipaddresslocation.org/ I've collected
about 16,000 ranges in the format

208.202.120.0 208.203.111.255
208.203.114.0 208.203.244.127
...

I don't yet know how many individual IP's then ranges totals, but I
reckon we speak millions.

Now, when a user hits that certain webpage a lookup should be
performed, checking if user is in a range. If he is, he's banned from
that part of the page.

My idea is to save to a table (MSSQL) that contains 4 columns - one
column for each part of the IP.
First of all, you should convert each IP address to a single 32 bit
value. There is no reason to compare four values when you can compare one.
When I import the ranges I save each
IP in that interval, ending up with all (or so) current US IP-
addresses. Each of the four columns are indexed.
If only 10% of the IP range is allocated to US, that makes a table with
430 million records...

You should definitely store the ranges, not the individual IP addresses.
A lookup will then use a phonebook-kinda-lookup (SELECT COUNT(*) FROM
myTable WHERE col1=62 AND col2=63 AND col3=64 and col4=65). If it
returns 0, user is allowed.

Is that a crappy approach, or should I consider something else?
Thanks in advance for any input.

Regards /Snedker

--
Göran Andersson
_____
http://www.guffa.com
Jul 30 '08 #3
"Snedker" <Mo************@gmail.comwrote in message
news:a0**********************************@a1g2000h sb.googlegroups.com...
Is that a crappy approach,
Certainly not particularly efficient...
or should I consider something else?
As Göran has suggested, you should store the ranges as int, not char /
varchar - that will make the entire comparison logic a breeze.

Then, create a stored procedure which accepts a regular IP address as a
parameter and returns the number of "hits" against your table - so long as
the IP address ranges don't overlap, the only possible return values should
be 0 or 1.

Everything you need is here:
http://sqlserver2000.databases.aspfa...ql-server.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 30 '08 #4

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

Similar topics

3
by: p s | last post by:
hi can someone tell me how to ensure the height of my window is always exact? (excluding titlebar) in VB6 e.g. if i set the form to 300 pixels, then the total height of the form takes into...
21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
7
by: none | last post by:
I want to determine the outside (non local, a.k.a. 127.0.0.x) ip addresses of my host. It seems that the socket module provides me with some nifty tools for that but I cannot get it to work...
8
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
1
by: Abby | last post by:
I'm writing a code to send/receive udp packet. I'll receive ip address from user (this is the starting ip), then I'll ask user how many ip he wants to connect to. For examples: Please enter 1st...
0
by: Ricky Chan | last post by:
I am using DNSQuery API to get computer name from IP address. However, by below sample code, I don't know how to specify the DNS Address for the field (ByVal aipServers As Integer). any idea?...
4
by: Mark Rae | last post by:
Hi, Am currently in the process of migrating a whole heap of v1.1 ASP.NET solutions to v2.0, and would be interested to know what others are doing about excluding files from projects. I...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
20
by: Terry Olsen | last post by:
I'm writing an app that communicates with computers both inside and outside my router. So I need to determine by the remote host's IP address if I need to send them my LAN IP or my Internet IP. ...
2
by: nachotico | last post by:
hi i'm new using PHP here is what i need> i have a MySQL database that contain Decimal IPs -- the issue is that i don't know how to after extract them convert them to a real IP. here is what i...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.