public static bool IsValidIPv4WithNetmask(string address) { int num = address.IndexOf("/"); string text = address.Substring(num + 1); return(num > 0 && IPAddress.IsValidIPv4(address.Substring(0, num)) && (IPAddress.IsValidIPv4(text) || IPAddress.IsMaskValue(text, 32))); }
private static bool unsafeIsValidIPv6(string address) { if (address.Length == 0) { return(false); } int num = 0; string text = address + ":"; bool flag = false; int num2 = 0; int num3; while (num2 < text.Length && (num3 = text.IndexOf(':', num2)) >= num2) { if (num == 8) { return(false); } if (num2 != num3) { string text2 = text.Substring(num2, num3 - num2); if (num3 == text.Length - 1 && text2.IndexOf('.') > 0) { if (!IPAddress.IsValidIPv4(text2)) { return(false); } num++; } else { string s = text.Substring(num2, num3 - num2); int num4 = int.Parse(s, NumberStyles.AllowHexSpecifier); if (num4 < 0 || num4 > 65535) { return(false); } } } else { if (num3 != 1 && num3 != text.Length - 1 && flag) { return(false); } flag = true; } num2 = num3 + 1; num++; } return(num == 8 || flag); }
public static bool IsValid(string address) { return(IPAddress.IsValidIPv4(address) || IPAddress.IsValidIPv6(address)); }