
Introduction
If our computer is on a LAN and has a DNS server, we can use the code below to get its IP address from the Web host. This code is very simple. We use the Dns class to connect to the DNS server on our Local Area Network. Then it returns a IPHostEntry object as IPHost. IPHost contains properties including the IP Address...
Implementation
using System;
using System.Net;
using System.Net.Sockets;
class GTest
{
public static void Main()
{
string strHost;
Console.Write("Input host : "); strHost = Console.ReadLine();
IPHostEntry IPHost = Dns.Resolve(strHost); Console.WriteLine(IPHost.HostName); IPAddress [] address = IPHost.AddressList; Console.WriteLine("List IP {0} :",IPHost.HostName);
for(int i = 0;i< address.Length; i++) Console.WriteLine(address[i]);
}
}
Reference
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here