Last post Oct 10, 2014 11:37 AM by markfitzme
Oct 09, 2014 07:59 AM|crazyim|LINK
How can i get IP address of Client system not a hosted or server system in asp.net?
I've hosted one asp.net application and want to prevent unauthorised access of application binding ip and mac address of computer.
Oct 09, 2014 08:23 AM|AidyF|LINK
that will give you the IP address of the machine making the request which may or may not be the client depending on if the client uses a proxy server. That is all you can get, you can't get the user's MAC address at all. For any follow up question you
might have, just assume the answer is "no" :)
Oct 09, 2014 08:31 AM|Rion Williams|LINK
Retrieving the IP Address
You could easily retrieve the client's IP Address using something like the following function :
protected string GetIPAddress()
// Gets the current context
System.Web.HttpContext context = System.Web.HttpContext.Current;
// Checks the HTTP_X_FORWARDED_FOR Header (which can be multiple IPs)
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
//If that is not empty
// Grab the first address
string addresses = ipAddress.Split(',');
if (addresses.Length != 0)
// Otherwise use the REMOTE_ADDR Header
You can find an extensive discussion here that mentions several techniques and information about fetching IP Addresses in .NET.
Regarding the MAC Address
I don't believe that you would be able to get an actual MAC Address of a remote user that connects to your site as the client's MAC Address isn't going to be sent across using the HTTP Protocol (in addition to the fact that things like firewalls and
proxies would also complicate things).
To retrieve a MAC Address would require something that exceeds the basic scope of ASP.NET (such as a Flash or ActiveX plug-in) and you would likely want to consider why you were looking to grab it.
Oct 10, 2014 11:37 AM|markfitzme|LINK
In addition to what RION mentions regarding the MAC address, that's not information that is transmitted to the web server in a way that is accessible. It's also not something necessarily available for use outside the local network and chances are, not transmitted
to your web server when the user makes a request.
Filtering by IP also is difficult since you could have an entire group of people that only appears as a single IP since they are behind a network modem and are using internal DHCP. In this case you will always get the internet facing IP address. Unless that
IP address is static, it's also subject to change so it becomes very difficult to restrict.