/// <summary> /// 查询ip信息 /// </summary> /// <param name="ip"></param> /// <returns></returns> public static TaobaoIP GetIP(string ip) { System.Net.WebClient client = new System.Net.WebClient(); try { string data = client.DownloadString("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip); //当code==1时,表示失败 if (data.IndexOf("\"code\":1") > -1) { return(new TaobaoIP() { code = 1, errorMsg = data }); } using (System.IO.MemoryStream mm = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(data))) { System.Runtime.Serialization.Json.DataContractJsonSerializer myJson = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(TaobaoIP)); TaobaoIP item = (TaobaoIP)myJson.ReadObject(mm); return(item); } } catch (Exception ex) { return(new TaobaoIP() { code = 1, errorMsg = ex.Message, data = new TaobaoIP_Data() { } }); } }
/// <summary> /// 根据域名返回域名的ip信息 /// </summary> /// <param name="domain"></param> /// <returns></returns> public static TaobaoIP[] GetDomain(string domain) { System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(domain); TaobaoIP[] result = new TaobaoIP[ips.Length]; for (int i = 0, j = ips.Length; i < j; i++) { result[i] = GetIP(ips[i].ToString()); } return(result); }
/// <summary> /// 根据域名返回域名的ip信息 /// </summary> /// <param name="domain"></param> /// <returns></returns> public static TaobaoIP[] GetDomain(string domain) { System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(domain); TaobaoIP[] result = new TaobaoIP[ips.Length]; for (int i = 0, j = ips.Length; i < j; i++) { result[i] = GetIP(ips[i].ToString()); } return result; }