Pages

Sunday, December 8, 2013

How to find hostname of a computer in c#.net

The System.Net classes provide functionalities that is similar to Microsoft WinInet API , it allows classes to communicate with other applications by using the Hypertext Transfer Protocol (HTTP), Transmission Control Protocol (TCP), User Datagram Protocol (UDP), and Socket Internet protocols.
The following C# program show how to find the Host name of a computer.

  Dns.GetHostName()

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

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

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show (Dns.GetHostName());
        }
    }
}

No comments:

Post a Comment