This is a C# Program to display the IP address of the machine.
This C# Program Displays the IP Address of the Machine.
It first obtains the Host Name and gets the IP address with the Host Name.
Here is source code of the C# Program to Display the IP Address of the Machine. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Display the IP Address of the Machine */ using System; using System.Net; namespace Program { class Program { static void Main() { //getting the Host Name. String strHostName = string.Empty; strHostName = Dns.GetHostName(); Console.WriteLine("Local Machine's Host Name: " + strHostName); IPHostEntry ipEntry = Dns.GetHostEntry(strHostName); // Using Host Name,IP address is obtained. IPAddress[] addr = ipEntry.AddressList; for (int i = 0; i < addr.Length; i++) { Console.WriteLine("IP Address {1} : ",addr[i].ToString()); } Console.ReadLine(); } } }
In this C# program, the IP address method obtains the selected server IP address information. It then displays the type of address family supported by the server and its IP address in standard and byte format. We are getting the server related information. For loop on the Address List is used to print the type of address family supported by the server.
Local Machine's Host Name : win7-pc IP Address : 192.168.1.2
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Check MCA Books
- Apply for Computer Science Internship
- Check Computer Science Books
- Practice MCA MCQs
- Practice Computer Science MCQs