Displays your IP address and hostname

September 17, 2008 by admin  
Filed under C Sharp

This example will display your IP address and hostname using C#

using System;
using System.Net;
class MYDns
{
public static void Main ()
{
string hostName = Dns.GetHostName();
Console.WriteLine("Local hostname: {0}", hostName);
IPHostEntry myself = Dns.GetHostByName(hostName);
foreach (IPAddress address in myself.AddressList)
{
Console.WriteLine("IP Address: {0}", address.ToString());
}
}
}

Related posts:

  1. find the hostname for a known IP address find the hostname for a known IP address with C...
  2. perform a DNS query perform a DNS query on a domain name using C...
  3. get ip address get ip address with VB.net Module Module1 Sub Main() Dim...
  4. Log users IP address This ASP example will retrieve a visitors IP address and...
  5. Display network information using Powershell  This example will display various snippets of network related information...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!