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.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for C# Internship
- Practice MCA MCQs
- Buy MCA Books
- Apply for Computer Science Internship
- Practice Computer Science MCQs