
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to Display Hostname and IP address
To find the hostname, use the Dns.GetHostName() method in C# −
String hostName = string.Empty; hostName = Dns.GetHostName(); Console.WriteLine("Hostname: "+hostName);
Now, use the IPHostEntry.AddressList Property to get IP Address −
IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList;
Example
Try the following code to display hostname and IP address −
using System; using System.Net; class Program { static void Main() { String hostName = string.Empty; hostName = Dns.GetHostName(); Console.WriteLine("Hostname: "+hostName); IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList; for (int i = 0; i < address.Length; i++) { Console.WriteLine("IP Address {1} : ",address[i].ToString()); } Console.ReadLine(); } }
- Related Articles
- Program to display hostname and IP address C
- Python program to Display Hostname and IP address?
- C Program to display hostname and IP address
- Java program to display Hostname and IP address
- Difference between Static IP Address and Dynamic IP Address
- C Program to validate an IP address
- JavaScript program to retrieve clients IP address
- Display the Host Name and IP Address on a Tkinter Window
- Difference between IP Address and MAC Address
- Difference between MAC Address and IP Address
- How to display the IP Address of the Machine using C#?
- Program to convert IP address to hexadecimal in C++
- Java program to convert Byte array to IP Address
- Java program to Get IP address of the system
- C# program to find IP Address of the client

Advertisements