Get public/external IP address?

前端 未结 26 2233
鱼传尺愫
鱼传尺愫 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 14:46

    I found that http://checkip.dyndns.org/ was giving me html tags I had to process but https://icanhazip.com/ was just giving me a simple string. Unfortunately https://icanhazip.com/ gives me the ip6 address and I needed ip4. Luckily there are 2 subdomains that you can choose from, ipv4.icanhazip.com and ipv6.icanhazip.com.

            string externalip = new WebClient().DownloadString("https://ipv4.icanhazip.com/");
            Console.WriteLine(externalip);
            Console.WriteLine(externalip.TrimEnd());
    

提交回复
热议问题