• <bdo id='j8R6s'></bdo><ul id='j8R6s'></ul>

    <i id='j8R6s'><tr id='j8R6s'><dt id='j8R6s'><q id='j8R6s'><span id='j8R6s'><b id='j8R6s'><form id='j8R6s'><ins id='j8R6s'></ins><ul id='j8R6s'></ul><sub id='j8R6s'></sub></form><legend id='j8R6s'></legend><bdo id='j8R6s'><pre id='j8R6s'><center id='j8R6s'></center></pre></bdo></b><th id='j8R6s'></th></span></q></dt></tr></i><div id='j8R6s'><tfoot id='j8R6s'></tfoot><dl id='j8R6s'><fieldset id='j8R6s'></fieldset></dl></div>
  1. <small id='j8R6s'></small><noframes id='j8R6s'>

  2. <tfoot id='j8R6s'></tfoot>
  3. <legend id='j8R6s'><style id='j8R6s'><dir id='j8R6s'><q id='j8R6s'></q></dir></style></legend>

      获取公共 Internet IP 地址/地理位置的智能方法

      时间:2023-09-17

      • <bdo id='S3Ih8'></bdo><ul id='S3Ih8'></ul>
      • <legend id='S3Ih8'><style id='S3Ih8'><dir id='S3Ih8'><q id='S3Ih8'></q></dir></style></legend>
          <i id='S3Ih8'><tr id='S3Ih8'><dt id='S3Ih8'><q id='S3Ih8'><span id='S3Ih8'><b id='S3Ih8'><form id='S3Ih8'><ins id='S3Ih8'></ins><ul id='S3Ih8'></ul><sub id='S3Ih8'></sub></form><legend id='S3Ih8'></legend><bdo id='S3Ih8'><pre id='S3Ih8'><center id='S3Ih8'></center></pre></bdo></b><th id='S3Ih8'></th></span></q></dt></tr></i><div id='S3Ih8'><tfoot id='S3Ih8'></tfoot><dl id='S3Ih8'><fieldset id='S3Ih8'></fieldset></dl></div>

            • <tfoot id='S3Ih8'></tfoot>

              <small id='S3Ih8'></small><noframes id='S3Ih8'>

                  <tbody id='S3Ih8'></tbody>
                本文介绍了获取公共 Internet IP 地址/地理位置的智能方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在本地网络上有一台计算机,位于 NAT 路由器后面.我有一些 192.168.0.x 地址,但我真的很想知道我的公共 IP 地址,而不是

                I have a computer on the local network, behind a NAT router. I have some 192.168.0.x addresses, but I really want to know my public IP address, not something mentioned in

                如何获取运行我的 C# 应用程序的服务器的 IP 地址?

                如何在C#中获取机器的IP地址

                我需要 C# 代码.

                有可能吗?如果有,怎么做?

                Is it possible? If so, how?

                推荐答案

                经过一番搜索,通过扩展我的需求,我发现这不仅可以获得 IP,还可以获得 GEO-location:

                After some search, and by expanding my requirements, I found out that this will get me not only the IP, but GEO-location as well:

                class GeoIp
                {
                    static public GeoIpData GetMy()
                    {
                        string url = "http://freegeoip.net/xml/";
                        WebClient wc = new WebClient();
                        wc.Proxy = null;
                        MemoryStream ms = new MemoryStream(wc.DownloadData(url));
                        XmlTextReader rdr = new XmlTextReader(url);
                        XmlDocument doc = new XmlDocument();
                        ms.Position = 0;
                        doc.Load(ms);
                        ms.Dispose();
                        GeoIpData retval = new GeoIpData();
                        foreach (XmlElement el in doc.ChildNodes[1].ChildNodes)
                        {
                            retval.KeyValue.Add(el.Name, el.InnerText);
                        }
                        return retval;
                    }
                }
                

                返回 XML,因此键/值字典将按如下方式填充:

                XML returned, and thus key/value dictionary will be filled as such:

                <Response>
                    <Ip>93.139.127.187</Ip>
                    <CountryCode>HR</CountryCode>
                    <CountryName>Croatia</CountryName>
                    <RegionCode>16</RegionCode>
                    <RegionName>Varazdinska</RegionName>
                    <City>Varazdinske Toplice</City>
                    <ZipCode/>
                    <Latitude>46.2092</Latitude>
                    <Longitude>16.4192</Longitude>
                    <MetroCode/>
                </Response>
                

                为了方便,返回类:

                class GeoIpData
                {
                    public GeoIpData()
                    {
                        KeyValue = new Dictionary<string, string>();
                    }
                    public Dictionary<string, string> KeyValue;
                }
                

                这篇关于获取公共 Internet IP 地址/地理位置的智能方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:C#的纬度和经度边界框? 下一篇:检查点是否在圆圈内

                相关文章

              1. <i id='5MAIv'><tr id='5MAIv'><dt id='5MAIv'><q id='5MAIv'><span id='5MAIv'><b id='5MAIv'><form id='5MAIv'><ins id='5MAIv'></ins><ul id='5MAIv'></ul><sub id='5MAIv'></sub></form><legend id='5MAIv'></legend><bdo id='5MAIv'><pre id='5MAIv'><center id='5MAIv'></center></pre></bdo></b><th id='5MAIv'></th></span></q></dt></tr></i><div id='5MAIv'><tfoot id='5MAIv'></tfoot><dl id='5MAIv'><fieldset id='5MAIv'></fieldset></dl></div>
              2. <tfoot id='5MAIv'></tfoot>
                  <bdo id='5MAIv'></bdo><ul id='5MAIv'></ul>

                    <small id='5MAIv'></small><noframes id='5MAIv'>

                    <legend id='5MAIv'><style id='5MAIv'><dir id='5MAIv'><q id='5MAIv'></q></dir></style></legend>