WEBSITE

Get This Machine’s Hostname and IP Address

9/26/2010 7:34:03 PM
You want to retrieve the current machine’s hostname and IP addresses.
string hostname = Dns.GetHostName();
Console.WriteLine("Hostname: {0}", hostname);
IPAddress[] addresses = Dns.GetHostAddresses(hostname);
foreach (IPAddress addr in addresses)
{
Console.WriteLine("IP Address: {0} ({1})",
addr.ToString(), addr.AddressFamily);
}

Here is the output on my machine. Notice the IPv6 addresses in the list:

Hostname: Ben-Desktop
IP Address: fe80::2c4c:372:e7ee:35b7%14 (InterNetworkV6)
IP Address: fe80::c1aa:9268:a7f0:a203%8 (InterNetworkV6)
IP Address: 192.168.1.2 (InterNetwork)
IP Address: 2001:0:4137:9e50:2c4c:372:e7ee:35b7 (InterNetworkV6)

Other  
 
Most View
Asus Transformer AiO P1801 All-In-One PC And Tablet - Hidden Tablet
Pioneer HTIB Surround Sound Systems With Prices Ranging From $360
Create And Share Your First Photo Journal
iPad Mini Test (Part 2)
The Best Mobile Apps (Part 2) - Pages
EA4500 – Cheap Router With Wavebands
Overview On UPnP Network Protocol (Part 2)
The Assemblage Of GeForce GTX 650 Ti Graphics Cards (Part 2)
Sharepoint 2010 : Business Connectivity Services - Adding Security Trimming to .NET Connectors
Fujifilm FinePix S4800 - Versatile Camera With Large Zoom And Manual Controls (Part 2)
Top 10
Sharepoint 2013 : Farm Management - Disable a Timer Job,Start a Timer Job, Set the Schedule for a Timer Job
Sharepoint 2013 : Farm Management - Display Available Timer Jobs on the Farm, Get a Specific Timer Job, Enable a Timer Job
Sharepoint 2013 : Farm Management - Review Workflow Configuration Settings,Modify Workflow Configuration Settings
Sharepoint 2013 : Farm Management - Review SharePoint Designer Settings, Configure SharePoint Designer Settings
Sharepoint 2013 : Farm Management - Remove a Managed Path, Merge Log Files, End the Current Log File
SQL Server 2012 : Policy Based Management - Evaluating Policies
SQL Server 2012 : Defining Policies (part 3) - Creating Policies
SQL Server 2012 : Defining Policies (part 2) - Conditions
SQL Server 2012 : Defining Policies (part 1) - Management Facets
Microsoft Exchange Server 2010 : Configuring Anti-Spam and Message Filtering Options (part 4) - Preventing Internal Servers from Being Filtered