-1

このコードを使用して、IPアドレスに基づいてユーザーの場所を取得しています。場所、国コードは返されません...データテーブルのすべての列はIPを除いて空白です ここに画像の説明を入力してください

string i = "aa.b.23.58";
            DataTable dt = GetLocation(i.Trim());
     public DataTable GetLocation(string strIPAddress)
        {
            //Create a WebRequest with the current Ip
        WebRequest _objWebRequest =
            WebRequest.Create("http://freegeoip.appspot.com/xml/"  +strIPAddress);


        //Create a Web Proxy
        WebProxy _objWebProxy =
           new WebProxy("http://freegeoip.appspot.com/xml/"
                     + strIPAddress, true);

        //Assign the proxy to the WebRequest
        _objWebRequest.Proxy = _objWebProxy;

        //Set the timeout in Seconds for the WebRequest
        _objWebRequest.Timeout = 2000;

        try
        {
            //Get the WebResponse 
            WebResponse _objWebResponse = _objWebRequest.GetResponse();
            //Read the Response in a XMLTextReader
            XmlTextReader _objXmlTextReader
                = new XmlTextReader(_objWebResponse.GetResponseStream());

            //Create a new DataSet
            DataSet _objDataSet = new DataSet();
            //Read the Response into the DataSet
            _objDataSet.ReadXml(_objXmlTextReader);

            return _objDataSet.Tables[0];
        }
        catch
        {
            return null;
        }
    } // End of GetLocation 
4

1 に答える 1

0

このサンプルを試して くださいhttp://www.codeproject.com/Articles/3265/GeoIP-Where-are-your-internet-visitors-coming-from

freegeoip.appspot.comに問題がある可能性があります

プロジェクト内の場所dbへのIPを保持できます。

于 2012-10-20T16:02:31.770 に答える