How To Get Local IP In C#

this is a simple code to get the local ip on c# first add imports system.net; namespace and add this sub

//Author : Mohamed Shimran
//Blog : http://www.ultimateprogrammingtutorials.blogspot.com

   public string GetIp()
        {
            System.Net.IPAddress[] IP = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
            for (int n = 0; n < IP.Length; n++)
            {
                return IP[n].ToString();
            }

        }
now you can add this code to a click event or any other events to get the ip address


  
   MessageBox.Show(GetIP());

1 comments:

Post a Comment