/// <summary> /// 判断地址是不是局域网地址 /// </summary> /// <param name="address"></param> /// <returns></returns> public static bool IsLocalAddress(this IPAddress address) { var parts = address.GetIntPart(); if (address.IsA()) { if (parts[0] == 10) { return true; } } if (address.IsB()) { if (parts[0] == 172) { if (parts[1] >= 16 && parts[1]<= 31) { return true; } } } if (address.IsC()) { if (parts[0] == 192 && parts[1] == 168) { return true; } } return false; }
/// <summary> /// 是不是E类地址(广播) /// </summary> /// <param name="address"></param> /// <returns></returns> public static bool IsE(this IPAddress address) { var parts = address.GetIntPart(); return parts[0] >= 240 && parts[0] <= 255; }
/// <summary> /// 是不是D类地址(多点广播) /// </summary> /// <param name="address"></param> /// <returns></returns> public static bool IsD(this IPAddress address) { var parts = address.GetIntPart(); return parts[0] >= 224 && parts[0] <= 239; }
/// <summary> /// 是不是C类地址 /// </summary> /// <param name="address"></param> /// <returns></returns> public static bool IsC(this IPAddress address) { var parts = address.GetIntPart(); return parts[0] >= 192 && parts[0] <= 223; }
/// <summary> /// 是不是B类地址 /// </summary> /// <param name="address"></param> /// <returns></returns> public static bool IsB(this IPAddress address) { var parts = address.GetIntPart(); return parts[0] >= 128 && parts[0] <= 191; }
/// <summary> /// 是不是A类地址 /// </summary> /// <param name="address"></param> /// <returns></returns> public static bool IsA(this IPAddress address) { var parts = address.GetIntPart(); return(parts[0] >= 1 && parts[0] <= 126); }