Net-informations.com
SiteMap  | About    

How to find IP Adress of a computer

Network programming in windows is possible with sockets . C# simplifies network programming through its namespaces like System.Net and System.Net.Sockets . The System.Net classes provide functionalities that is similar to Microsoft WinInet API.

The System.net namespace provides the information about IP Address . The following C# program shows how to find the IP Address of a host.

csharp_ip_address



using System;
using System.Windows.Forms;
using System.Net;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                IPHostEntry hostname = Dns.GetHostByName(textBox1.Text );
                IPAddress[] ip = hostname.AddressList;
                textBox2.Text  = ip[0].ToString(); 
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

If you pass localhost in GetHostByName return the IP Address of local machine .






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.