/// <summary> /// 检测IP /// </summary> /// <param name="strIP"></param> /// <returns></returns> public static bool PingIP(string strIP) { if (!IsValidIP(strIP)) { return false; } System.Net.NetworkInformation.Ping psender = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply prep = psender.Send(strIP, 500, Encoding.Default.GetBytes("afdafdadfsdacareqretrqtqeqrq8899tu")); if (prep.Status == System.Net.NetworkInformation.IPStatus.Success) { return true; } return false; } /// <summary> /// 验证IP /// </summary> /// <param name="ip"></param> /// <returns></returns> public static bool IsValidIP(string ip) { if (System.Text.RegularExpressions.Regex.IsMatch(ip, "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}")) { string[] ips = ip.Split('.'); if (ips.Length == 4 || ips.Length == 6) { if (System.Int32.Parse(ips[0]) < 256 && System.Int32.Parse(ips[1]) < 256 & System.Int32.Parse(ips[2]) < 256 & System.Int32.Parse(ips[3]) < 256) return true; else return false; } else { return false; } } else return false; }