IPAddress range validation

  • Thread starter Thread starter Chen
  • Start date Start date
C

Chen

Hi,
I'm trying to the best way to validate that a specified
IP is inside a known range of IP. The IP is held in an
IPAddress type which hold the actual IP in as long and so
the statement:
224.1.0.0 > 224.0.1.0 does not necesarily translate to:
480 > 65760 (which is the representation of these IP as
long).
I would expect that i would able to do something like:
ipAddress.Address > pAddress1.Address
I know I can do all kind of string or mathematical
manipulations but I am hoping for a more elegant solution
that will take advantage of the fact that the data is
held as IPAddress type.
Thanks,
Chen
 
Hi Chen,

We can't compare two IpAddress objects with symbol ">" or "<" directly. I
think you may consider converting them to Byte array first with IPAddress
class's GetAddressBytes method, and then compare the byte array to get the
result.

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Luke,
Thanks. This is pretty much what I did. I was just hoping
for something more elegant. Maybe in the next framework :)
Chen
 
Back
Top