Help with Network Address Math

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: AZ Pete
Date:  
Subject: Help with Network Address Math
Calling all network gurus :)

My IP network address math is rather rusty (it's been a long time!!). I have need to calculate whether a given client
IP address is within a given network. Additionally, if there are a list of given networks, which one is the most
specific. I need the math formulas to calculate these figures for use within an application.

Examples:
Given the network: 192.168.1.0/24
Given IP address is: 192.168.1.100

What is the formula to determine if this client's IP address falls within the network's range.

Further example
Given these networks: 192.168.1.0/24 and 192.168.0.0/16
and the client IP of: 192.168.1.100

In this case the client's IP falls within both networks. What is the formula to determine which network is the more
specific one?

Any help would be most appreciated.
Thanks,
Peter