Get public/external IP address?

前端 未结 26 2302
鱼传尺愫
鱼传尺愫 2020-11-22 14:32

I cant seem to get or find information on finding my routers public IP? Is this because it cant be done this way and would have to get it from a website?

26条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 14:59

    using System.Net;
    
    private string GetWorldIP()
    {
        String url = "http://bot.whatismyipaddress.com/";
        String result = null;
    
        try
        {
            WebClient client = new WebClient();
            result = client.DownloadString(url);
            return result;
        }
        catch (Exception ex) { return "127.0.0.1"; }
    }
    

    Used loopback as fallback just so things don't fatally break.

提交回复
热议问题