6

I'm Migrating Windows Form Class Library to Metro App Class Library. In that there's a code-block which gives the IPAddress from the Host Name, below,

IPHostEntry ipHostInfo = Dns.GetHostEntry(Address);   
IPAddress ipAddress = ipHostInfo.AddressList[0];// IPAddress.Parse(address);
IPEndPoint endPoint = new IPEndPoint(ipAddress, Port);

eg:

Address : talk.google.com

ipAddress : xx.xxx.xxx.xx

But I've seen that there is no IPHostEntry or Dns or IPAddress in Metro App System.Net. .

If anybody knows means please tell me the replacement for these in windows 8 metro app.

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Gopinath Perumal
  • 2,258
  • 3
  • 28
  • 41

2 Answers2

2
using System.Threading.Tasks;

public async static Task<string> ResolveDNS(string remoteHostName)
    {
        if (string.IsNullOrEmpty(remoteHostName))
            return string.Empty;

        string ipAddress = string.Empty;

        try
        {
            IReadOnlyList<EndpointPair> data =
              await DatagramSocket.GetEndpointPairsAsync(new HostName(remoteHostName), "0");

            if (data != null && data.Count > 0)
            {
                foreach (EndpointPair item in data)
                {
                    if (item != null && item.RemoteHostName != null &&
                                  item.RemoteHostName.Type == HostNameType.Ipv4)
                    {
                        return item.RemoteHostName.CanonicalName;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ipAddress = ex.Message;
        }

        return ipAddress;
    } 
depicus
  • 301
  • 4
  • 19
1

check How to resolve a hostname to an IP address in Metro/WinRT? and replace 'http' to https and try.

i.e

await clientSocket.ConnectAsync(serverHost, "https");
Community
  • 1
  • 1