Monday 6 November 2017

Get IPAddress and Machine Name in C#.

Whenever we are Creating any Kind Of Websites at that time we are very much eager about to know the IPAddress and Machine Name of that User.
Because from the IPAddress we can easily find out the Person login from Which Country,City etc.
To Find out IPAddress and Machine Name in C# we need to do following things,

First add using System.Net namespace.

After that we need to write few lines of Code and easily we can retrieve IPAddress and Machine Name which is as follows,


IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
string IpAddress = Convert.ToString(ipHostInfo.AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork));
string MachineName = ipHostInfo.HostName;

Now we got the IPAddress and Machine Name.

0 comments:

Post a Comment