How to get *internet* IP?

后端 未结 15 2110
刺人心
刺人心 2020-11-29 02:57

Imagine a situation, I have PC with two lan cards, one is connected to internet another is connected to local network, how can I detect IP which is connected to internet wi

15条回答
  •  情话喂你
    2020-11-29 03:40

    I suggest this simple code since tracert is not always effective and whatsmyip.com is not specially designed for that purpose :

    private void GetIP()
    {
        WebClient wc = new WebClient();
        string strIP = wc.DownloadString("http://checkip.dyndns.org");
        strIP = (new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")).Match(strIP).Value;
        wc.Dispose();
        return strIP;
    }
    

提交回复
热议问题