Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Finding IP Address information of your computer in C#

The below code will be useful in finding IP address of your local computer.
Please include System.Net directory.

  1. using System;
  2. using System.Net;
  3.  
  4. public class ForgetCode
  5. {
  6. public static void Main()
  7. {
  8. UseDNS();
  9. }
  10.  
  11. public static void UseDNS()
  12. {
  13. string hostName = Dns.GetHostName();
  14. Console.WriteLine("Host Name = " + hostName);
  15. IPHostEntry local = Dns.GetHostByName(hostName);
  16. foreach (IPAddress ipaddress in local.AddressList)
  17. {
  18. Console.WriteLine("IPAddress = " + ipaddress.ToString());
  19. }
  20. }
  21. }

Output:
Host Name = Your-PC Name
IPAddress = Your IP address