• <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 地址/地理位置的智能方法

      Smart way to get the public Internet IP address/geo loc(获取公共 Internet IP 地址/地理位置的智能方法)

      • <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# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                IBM.Data.DB2.Core connection problems(IBM.Data.DB2.Core 连接问题)
                Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                Datetime field overflow with IBM Data Server Client v9.7fp5(IBM Data Server Client v9.7fp5 的日期时间字段溢出)
                Using entity Framework with .NET Core and DB2(将实体框架与 .NET Core 和 DB2 结合使用)
              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>
                <tfoot id='5MAIv'></tfoot>
                  <bdo id='5MAIv'></bdo><ul id='5MAIv'></ul>

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

                          <tbody id='5MAIv'></tbody>

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