CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      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
         C# Source Code Download           Print Source Code
         How to find IP Adress of a computer - Download
        
C# Tutorial

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 .

CSharp Communications Related Contents
*     How to send email from C#
*     How to send email with attachment from C#
*     How to send html email from C#
*     How to send cdo email from C#
*     How to find hostname of a computer
*     How to read URL Content from webserver
*     How to C# Socket programming
*     C# Server Socket program
*     C# Client Socket program
*     C# Multi threaded socket programming
*     C# Multi threaded Server Socket programming
*     C# Multi threaded Client Socket programming
*     How to C# Chat server programming
*     How to C# Chat Server
*     How to C# Chat Client


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.