Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

How can we check whether a particular IP say 194.66.82.11 is in a range of 194.66.82.00 and 194.66.180.255 in C#.

Thanks in advance.

Regards
Santhosh
Posted

 
Share this answer
 
Just split it into the four fields and do some compare operations. You could convert each quad to an integer to help things along.
 
Share this answer
 
IP addresses are usually transmitted or typed as strings.
IP as strings can't be compared, you must normalise before comparing.

An IP adress is made of 4 numeric parts with points as separator: "aaa.bbb.ccc.ddd"
1) you have to split the address in its 4 parts.
2) Convert each string part into numeric.
3) Combine them into 1 numeric value NumIP= (( aaa * 256 + bbb ) * 256 + ccc ) * 256 + ddd

Then you can compare numeric values.

Not actual c# code, I let you deal with details.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900