Smart way to get the public Internet IP address/geo loc

后端 未结 9 2018
野趣味
野趣味 2021-01-01 05:41

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 somethin

9条回答
  •  攒了一身酷
    2021-01-01 06:09

    If you are worried about connection lose or the availability of the site, you can also try this way to avoid that issue by including above suggestions.

        using System.Threading;
    
        Task[] tasks = new[]
        {
          Task.Factory.StartNew( () => new System.Net.WebClient().DownloadString(@"http://icanhazip.com").Trim() ),
          Task.Factory.StartNew( () => new System.Net.WebClient().DownloadString(@"http://checkip.dyndns.org").Trim() )
        };
    
        int index = Task.WaitAny( tasks );
        string ip = tasks[index].Result;
    

    Hope this one also help.

提交回复
热议问题