-
June 6th, 2006, 05:55 PM
#1
validate client ip address is within range
I have a range of IP address, 10.0.0.0/8 (which translates 10.0.0.0 to 10.0.0.255).... and I have an IP that I would like to validate is within this range. Like so...
Code:
string sClientIP = "10.0.0.2";
string sValidIPRange = "10.0.0.0/8";
bool bReturn = IsInRange(sClientIP,sValidIPRange);
Question is... what does the IsInRange fxn look like and is there such a function already available in .NET? How do I parse out a block of IPs (10.0.0.0 to 10.0.0.255) from a single string that uses the slash (/) notation?
-
June 7th, 2006, 03:58 AM
#2
Re: validate client ip address is within range
Code:
string[] parts = sValidIPRange.Split('.');
string rangePart = parts[parts.Length - 1];
string[] range = rangePart .Split('/');
int startRange,endRange;
bool res;
res = Int32.TryParse(range[0],startRange);
res = Int32.TryParse(range[1],endRange);
parts = sClientIP.Split('.');
int lastPart;
res = Int32.TryParse(parts[parts.Length - 1],lastPart);
return lastPart>=startRange && lastPart<=endRange;
-
June 7th, 2006, 05:38 AM
#3
Re: validate client ip address is within range
Originally Posted by sambo
I have a range of IP address, 10.0.0.0/8 (which translates 10.0.0.0 to 10.0.0.255).... and I have an IP that I would like to validate is within this range. Like so...
Code:
string sClientIP = "10.0.0.2";
string sValidIPRange = "10.0.0.0/8";
bool bReturn = IsInRange(sClientIP,sValidIPRange);
Question is... what does the IsInRange fxn look like and is there such a function already available in .NET? How do I parse out a block of IPs (10.0.0.0 to 10.0.0.255) from a single string that uses the slash (/) notation?
>>>
use System.Net.IPAddress
Search Google for help
- Software Architect
-
June 7th, 2006, 10:40 AM
#4
Re: validate client ip address is within range
I am very familiar with the IPAddress class... but how does that answer my question? I don't see any functionality in that class that does what I am asking. Am I missing something?
-
June 7th, 2006, 10:30 PM
#5
Re: validate client ip address is within range
u can validate IP addresses using regular expressions
-
June 8th, 2006, 03:04 PM
#6
Re: validate client ip address is within range
Originally Posted by pareshgh
use System.Net.IPAddress
Search Google for help
Originally Posted by sambo
I am very familiar with the IPAddress class... but how does that answer my question? I don't see any functionality in that class that does what I am asking. Am I missing something?
IPAddress class do not support range of IPs in the way you described (with slash). You will have to parse the string somehow to retrieve the range. You might use regular expressions as aniskhan said, or parse the string like I suggested.
-
June 8th, 2006, 03:10 PM
#7
Re: validate client ip address is within range
Check this out... its outstanding!
NetCalculator
-
June 8th, 2006, 06:37 PM
#8
Re: validate client ip address is within range
To pareshgh...
I find it very interesting that you would give me negative feedback on a question I posed that you yourself gave an insufficient answer to.
To answer your admonition about searching for the answer... I did search for the answer... and I finally found it after 3 DAYS!
If you don't like my question, then don't bother piping in with a mediocre reply.
-
June 9th, 2006, 06:27 AM
#9
Re: validate client ip address is within range
I must agree with sambo. It appears that pareshgh decided to give everybody bad reputation, regardless of the content of the message, although he gave answer which is not so good.
Well, I hope everybody will think twice before spreading bad reputation.
-
September 11th, 2006, 02:39 AM
#10
Re: validate client ip address is within range
I didn't really intend to decrease anyone's reputation..
thanks for pointing it out.
let me know how can I spread reputation for you all. thanks !!
bye and have a nice day..
- Software Architect
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
|