none
哪里有API可以获取外部IP地址 RRS feed

答案

  • 可以通过 DatagramSocket.GetEndpointPairsAsync ,获取远程IP地址。
    样例代码如下。

    private async void SampleMethod()
    {
                 try
                 {
                     Windows.Networking.HostName strHost = new Windows.Networking.HostName("www.google.com");
                     IReadOnlyList<Windows.Networking.EndpointPair> endPointPairList = await Windows.Networking.Sockets.DatagramSocket.GetEndpointPairsAsync(strHost, "0");
    
                    foreach(Windows.Networking.EndpointPair endPoint in endPointPairList) 
                     {
                         Debug.WriteLine("EndPoint is " + endPoint.RemoteHostName.RawName);
                     }
                 }
                 catch (Exception oEx)
                 {
                     Debug.WriteLine("Exception occurred: " + oEx.Message);
                 }
    }
    

     


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年3月25日 10:53
    版主