I want to get the IP Address and the MAC Address of the user who login to the system (web application). I am using these to line of codes
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
I am using this method to get the MAC address, but the problem is I am getting the MAC Address of all the Adapters of the computer.
HOW do I know which one is the right one?, how to get the right MAC Address of the device that is connected to my website??
and also how to get the IP of the adapter too.
when i try it on my pc it give 8 adapters with 8 MAC Addresses
I am trying on my pc, I have a wired connection connected to IntraNet, and a wireless connected to internet.
You can never get the MAC address of a user connected to your website, when a socket connection occurs between the destination (your website's server) and a source (client's computer) you can only get the source IP address, for the MAC address it's never sent over the socket connection (Client <--> Server), in order to get the IP address of a user:
using System.Net;
Private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length-1].ToString();
}
source: Here