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 member doesn't quite have enough reputation to be able to display their biography and homepage.