Good Afternoon,
I'm new to C# programming and I'm taking Networking this semester. The professor asks to write a program in C# Write a program to discover the IP address of your machine. Also an interesting modification to this program is to give the host name and let the program printout the IP address. So far I have this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Web;
namespace COMPUTER_IPADDRESS_FINDER
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCheckIP_Click(object sender, EventArgs e)
{
try
{
IPHostEntry hostname = Dns.GetHostEntry(txthostname.Text );
IPAddress[] ip = hostname.AddressList;
txtIpAddress.Text = ip[0].ToString();
txthostname.Text = Dns.GetHostName();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
In advance thank you for your cooperation.
Thank you