Abroad is also a more authoritative IP address library, and free of charge, the number of calls per day not more than 1000 free. More than another charge.
Public stringIp2country (stringIP) { Try { stringURL ="http://api.ipinfodb.com/v3/ip-country/?key=<your key,should regist first>&ip="+IP; stringrst = Httpcrossdomain.get (URL,10000); if(RST. Split (';'). Count () >=4) RST= rst. Split (';')[3]; Elserst=""; returnrst; } Catch { return "ERROR"; } }
/// <summary> ///cross-domain access/// </summary> /// <param name= "url" ></param> /// <param name= "param" ></param> /// <returns></returns> Public Static stringGet (stringUrlintTime =60000) {Uri address=NewUri (URL); HttpWebRequest Request= WebRequest.Create (address) asHttpWebRequest; Request. Method="GET"; Request. ContentType="Application/json;charset=utf-8";//"application/x-www-form-urlencoded";Request. Timeout =Time ; stringresult =""; using(HttpWebResponse response = Request.) GetResponse () asHttpWebResponse) {StreamReader Reader=NewStreamReader (response. GetResponseStream ()); Result=Reader. ReadToEnd (); } return(result); }
Get country based on IP