|
-
Feb 7th, 2014, 06:44 AM
#1
Thread Starter
Fanatic Member
SQL Server 2008 R2: Check if IP address is in a range
Hi,
I'm trying to write a SP to check if a passed in IP address is in a range e.g. equal to or between a start and an end address. e.g. -
Code:
Is 10.10.10.5 equal to or between 10.10.10.1 and 10.10.10.10
Regards Al
-
Feb 7th, 2014, 02:45 PM
#2
Addicted Member
Re: SQL Server 2008 R2: Check if IP address is in a range
I would typically have my front end do the checking for me.
-
Feb 8th, 2014, 03:44 AM
#3
Thread Starter
Fanatic Member
Re: SQL Server 2008 R2: Check if IP address is in a range
Hi,
Think I've got it whipped thanks, converting the IP address into a number (BigInt) -
I've not done any speed tests on these two methods -
This one uses PARSENAME to access the octets
http://www.firstbigstep.net/content/...umber_SQL.aspx
And this one uses a UDF split function to access the octets -
http://www.sqlservercentral.com/scri...laneous/30943/
At the moment I'm using the second one. I've also tweaked this second one to just validate the passed in IP address I.E. check that it has 4 octets and the numbers are between 0-255 returns a Boolean, I've called it IsValidIP (@IPAddress)
If anyone has any thoughts on the efficiencies of these two approaches I'd be glad to hear them.
Hopefully this helps someone in the future.
Cheers Al
PS - Currently our platform only supports V4 IP addresses
Last edited by aconybeare; Feb 8th, 2014 at 03:45 AM.
Reason: fix typo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|