How to

get host name and ip addresses

Published: 9. October 2011 | Updated: 9. October 2011
License: Microsoft Public License (MS-PL)
Categories: Network
Tags: C# Network
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Net;

Code

var hostName = Dns.GetHostName();

var addresses = Dns.GetHostAddresses(hostName);

foreach (IPAddress ipAddress in addresses)
{
    Console.WriteLine(ipAddress);
}
Send us feedback about this snippet »



Related Snippets: