none
How to get my public IP Address? RRS feed

Answers

  • Hello Jassim,

    1. As Sheng Jiang has mentioned, you need to obtain it from a web site that offers such information.

    2. One good site is https://www.ipify.org/

    3. The following C# code is taken directly from the many language samples provided in the site :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net;
    
    namespace ConsoleGetPublicIP
    {
        class Program
        {
            static void DisplayPublicIP()
            {
                WebClient webClient = new WebClient();
                string publicIp = webClient.DownloadString("https://api.ipify.org");
                Console.WriteLine("My public IP Address is: {0}", publicIp);
            }
    
            static void Main(string[] args)
            {
                DisplayPublicIP();
            }
        }
    }
    

    4. Hope this will help you get started.

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    • Marked as answer by Jassim Rahma Sunday, July 21, 2019 1:10 PM
    Sunday, July 21, 2019 1:30 AM

All replies

  • you gonna need some web site telling you that as there is no such information recorded locally. 

    some famous web sites include icanhazip.com and checkip.amazonaws.com. or you can set up your own server to return ip address on http web requests. 



    Visual C++ MVP

    Sunday, July 21, 2019 1:01 AM
  • Hello Jassim,

    1. As Sheng Jiang has mentioned, you need to obtain it from a web site that offers such information.

    2. One good site is https://www.ipify.org/

    3. The following C# code is taken directly from the many language samples provided in the site :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net;
    
    namespace ConsoleGetPublicIP
    {
        class Program
        {
            static void DisplayPublicIP()
            {
                WebClient webClient = new WebClient();
                string publicIp = webClient.DownloadString("https://api.ipify.org");
                Console.WriteLine("My public IP Address is: {0}", publicIp);
            }
    
            static void Main(string[] args)
            {
                DisplayPublicIP();
            }
        }
    }
    

    4. Hope this will help you get started.

    - Bio.


    Please visit my blog : http://limbioliong.wordpress.com/

    • Marked as answer by Jassim Rahma Sunday, July 21, 2019 1:10 PM
    Sunday, July 21, 2019 1:30 AM