How to get HostName | IP Address | Username ?

In this article you will get to know how we can get the Host Name, IP address, Current User and Current Directory

1. Host Name

Hostname = Environment.MachineName

2. IP Address

To get the IP address of a machine first of all we need to create a type of variable called DNS(Domain Name Service)

image

IP Address = Dns.GetHostByName(Dns.GetHostName()).AddressList(0).ToString()

3. Current User

CurrentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString

#4. Current Working Directory

CurrentWorkingDirectory = Environment.CurrentDirectory

I hope you enjoyed this article :star_struck:

3 Likes