WP7 Mango - How to get the IP address for a given host name

I need to get the IP address for a given host name from DnsEndPoint and convert it to IPEndPoint. How should I do it? WP7 does not have the Dns.GetHostEntry function, so is there a way to do this without creating a Socket, sending data to the host, and then receiving ping from the host and reading the RemoteEndPoint property to get the host IP address?

+5
source share
3 answers

Try using DeviceNetworkInformation.ResolveHostNameAsyncin a namespace Microsoft.Phone.Net.NetworkInformation, for example:

public void DnsLookup(string hostname)
{
    var endpoint = new DnsEndPoint(hostname, 0);
    DeviceNetworkInformation.ResolveHostNameAsync(endpoint, OnNameResolved, null);  
}

private void OnNameResolved(NameResolutionResult result)
{
    IPEndPoint[] endpoints = result.IPEndPoints;
    // Do something with your endpoints
}
+5
source

. , , ping. , ( , ) .

IP- , , , - IP-.

+2

, . IP- dns No-ip.

, , System.Net.Dns Windows Phone. , .

http://msdn.microsoft.com/en-us/library/system.net.dns.aspx

At the beginning of my application, I am going to create a web service call to a host (to the web server in it) requesting IPAddress. I think I will solve the problem in the meantime.

It could be a WCF service

[ServiceContract]
 public interface IService1
 { 
 [OperationContract]
 string GetIpAddress(string value);
 }

 public class Service1 : IService1
 {
  public string GetIpAddress()
    {
  // Add the proper error handling and collection matching of course
        IPAddress s = Dns.GetHostAddresses("www.mysite.com")[0];
        return s.ToString();
    }
  }

If you guys find a direct approach, please let me know.

+2
source

All Articles