判断当前主机是不是阿里云内网
static void Main(string[] args) { Console.WriteLine(IsAliyunInsideNetwork()); Console.WriteLine(Ping("oss-cn-qingdao.aliyuncs.com")); Console.ReadKey(); } /// <summary> /// 功能:判断本机是不是阿里云内网 /// 作者:黄海 /// 时间:2018-06-13 /// </summary> /// <returns></returns> public static bool IsAliyunInsideNetwork() { return Ping("oss-cn-qingdao-internal.aliyuncs.com"); } /// <summary> /// 是否能 Ping 通指定的主机 /// </summary> /// <param name="ip">ip 地址或主机名或域名</param> /// <returns>true 通,false 不通</returns> public static bool Ping(string ip) { var p = new System.Net.NetworkInformation.Ping(); var options = new System.Net.NetworkInformation.PingOptions {DontFragment = true}; var data = "Test Data!"; var buffer = Encoding.ASCII.GetBytes(data); const int timeout = 1000; // Timeout 时间,单位:毫秒 var reply = p.Send(ip, timeout, buffer, options); return reply != null && reply.Status == System.Net.NetworkInformation.IPStatus.Success; }