In this example, I’ll show How to get local machine ip address using C#
Here is source code of the C# Program to Display the IP Address of the Machine.The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
C# Code:
1 2 3 |
using System.Net; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
static void Main() { Console.WriteLine(Dns.GetHostName()); IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); foreach (IPAddress addr in localIPs) { Console.WriteLine(addr); } Console.ReadLine(); } |