- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the ip address in C#?
IP (Internet Protocol) Address is an address of your network hardware. It helps in connecting your computer to other devices on your network and all over the world. An IP Address is made up of numbers or characters.
All devices that are connected to an internet connection have a unique IP address which means there’s a need of billions of IP addresses. This requirement is fulfilled by the new IP version IPv6.
Private IP Address
A private IP address is the address of your device connected on the home or business network. If you have a few different devices connected to one ISP (Internet Service Provider), then all your devices will have a unique private IP address. This IP address cannot be accessed from devices outside your home or business network.
For example: 192.168.1.1
Example
class Program{ static void Main(string[] args){ string IPAddress = GetIPAddress(); System.Console.WriteLine(IPAddress); Console.ReadLine(); } public static string GetIPAddress(){ string IPAddress = string.Empty; IPHostEntry Host = default(IPHostEntry); string Hostname = null; Hostname = System.Environment.MachineName; Host = Dns.GetHostEntry(Hostname); foreach (IPAddress IP in Host.AddressList){ if (IP.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork){ IPAddress = Convert.ToString(IP); } } return IPAddress; } }
Output
192.168.1.1
- Related Articles
- How to get the IP Address of local computer using C/C++?
- How to get a Docker Container IP address?
- How to get IP address settings using PowerShell?
- How to get the IP address of android device programmatically?
- How to get the Android Emulator's IP address?
- How to get current Wi-Fi IP address in android?
- Java program to Get IP address of the system
- How can we get the client's IP address in ASP.NET MVC C#?
- Validate IP Address in C++
- Validate IP Address in C#
- How to get the Android Emulator's IP address using Kotlin?
- How to get the IP address of the Android device programmatically using Kotlin?
- How to get a Docker container's IP address from the host?
- How to display the IP Address of the Machine using C#?
- C Program to validate an IP address
