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.
In an open command line, type ping followed by the hostname (for example, ping dotcom-monitor.com). and press Enter. The command line will show the IP address of the requested web resource in the response. An alternative way to call Command Prompt is the keyboard shortcut Win + R.
Here is a simple method to find hostname and IP address using C program. gethostname() : The gethostname function retrieves the standard host name for the local computer. gethostbyname() : The gethostbyname function retrieves host information corresponding to a host name from a host database.
Typically you can find the IP address for a domain by pinging the domain. This can be done from your local PC. However, the steps may vary depending on the OS that you're using. To simplify this process, we can use an online Ping tool, such as https://ping.eu/ping/.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With