0
0
KYKenan Yusubov
The code first retrieves the hostname from the DNS server. It then loops through the array of IP addresses found in the retrieved hostname. For each IP address, it checks to see if the IP address is of the InterNetwork type. If it is, it prints out the IP address and then terminates the loop.
using System.Net;
using System.Net.Sockets;
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
// Get Ipv4 Address
Console.WriteLine(ip.ToString());
}
}
// Get the Name of HOSTΒ Β
string hostName = Dns.GetHostName();
Console.WriteLine(hostName);