CIDR validation W/ C#

  • Hi,

    Were you able to get any information on how to calculate CIDR notations? I am trying to do the same using VB6. Can you help me in any way? My email address: boyinapalli@hotmail.com

    Thanks.

    Bhagavan

  • yes over on the MSDN forums someone gave some code although it is very specific to c# and .net

    private bool IsInSubnet (string ipAddress, string cidr) {

    string [] parts = cidr.Split ('/');

    int baseAddress = BitConverter.ToInt32 (IPAddress.Parse (parts [0]).GetAddressBytes (), 0);

    int address = BitConverter.ToInt32 (IPAddress.Parse (ipAddress).GetAddressBytes (), 0);

    int mask = IPAddress.HostToNetworkOrder (-1 << (32 - int.Parse (parts [1])));

    return ((baseAddress & mask) == (address & mask));

    }

    you can read the whole post here: https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1955891&SiteID=1

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply