-2

i'm using ASP.NET webforms, and would like to get the ip and MAC address of a client visiting my site. Is it possible ?

Adam Bickels
  • 461
  • 12
  • 30

2 Answers2

0

You can get the IP address from Request.UserHostAddress.

You cannot get the MAC address.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

You can get IP address using Request.UserHostAddress or Request.ServerVariables["REMOTE_ADDR"]. If client is behind the proxy server then you can try to obtain his IP using ServerVariables["HTTP_X_FORWARDED_FOR"]. Read here for more details.

You can't get the MAC addresses unless your clients are on the same physical subnet as the server. To get MAC address within intranet

//get all nics
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
//display the physical address of the first nic in the array,
//which should correspond to our mac address
Label1.Text = nics[0].GetPhysicalAddress().ToString();

or read more here.

Community
  • 1
  • 1
user2316116
  • 6,726
  • 1
  • 21
  • 35