What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 38228 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET 4.0 > How to get MAC Address of client Machine ...
Bhavna81

How to get MAC Address of client Machine

Replies: 7 | Posted by: Bhavna81 on 6/3/2010 | Category: ASP.NET 4.0 Forums | Views: 23871 | Status: [Member]  


hello experts,
i m developing ASP.NET application. in that for the security purpose i want to use MAC address of the PC. for that i have wrote some code as:

NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

for (int j = 0; j <= 1; j++)
{
PhysicalAddress address = nics[j].GetPhysicalAddress();
byte[] bytes = address.GetAddressBytes();
for (int i = 0; i < bytes.Length; i++)
{
M = M + bytes.ToString("X2");
if (i != bytes.Length - 1)
{
M = M + ("-");
}
}
}

its working fine. i have host this application on local server in our office. NOW the problem is when user register himself from client machine, above code get the MAC address of server machine not of client machine.

Please Help....
thanks.

My problem is here.......that i want a client Machine's MAC Address when user register himself from client machine.......how can i


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Vuyiswamb
Vuyiswamb  
Posted on: 6/3/2010 5:07:43 PM
Level: NotApplicable | Status: [Member] [MVP] [Administrator]

The Problem here is that you are getting the IP locally on this line

 PhysicalAddress address = nics[j].GetPhysicalAddress();



use this to get the IP of a client

Request.UserHostAddress


Thank you for posting at Dotnetfunda
[Administrator]

Bhavna81, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Deeraj
Deeraj  
Posted on: 6/4/2010 6:39:01 AM
Level: Starter | Status: [Member]

Try this in case you have a load balancer:

public static string GetClientIPAddress(System.Web.HttpRequest httpRequest)
{
string OriginalIP = string.Empty;
string RemoteIP = string.Empty;

OriginalIP = httpRequest.ServerVariables["HTTP_X_FORWARDED_FOR"]; //original IP will be updated by Proxy/Load Balancer.

RemoteIP = httpRequest.ServerVariables["REMOTE_ADDR"]; //Proxy/Load Balancer IP or original IP if no proxy was used

if (OriginalIP != null && OriginalIP.Trim().Length > 0)
{
return OriginalIP + "(" + RemoteIP + ")"; //Lets return both the IPs.
}

return RemoteIP;
}


Hope that helps!

Bhavna81, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Bhavna81
Bhavna81  
Posted on: 6/4/2010 6:59:55 AM
Level: Starter | Status: [Member]

public static string GetClientIPAddress(System.Web.HttpRequest httpRequest)

{

string OriginalIP = string.Empty;

string RemoteIP = string.Empty;



OriginalIP = httpRequest.ServerVariables["HTTP_X_FORWARDED_FOR"]; //original IP will be updated by Proxy/Load Balancer.



RemoteIP = httpRequest.ServerVariables["REMOTE_ADDR"]; //Proxy/Load Balancer IP or original IP if no proxy was used



if (OriginalIP != null && OriginalIP.Trim().Length > 0)

{

return OriginalIP + "(" + RemoteIP + ")"; //Lets return both the IPs.

}



return RemoteIP;

}



How to call above function...

Bhavna81, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Deeraj
Deeraj  
Posted on: 6/4/2010 7:22:50 AM
Level: Starter | Status: [Member]


For Example:

In page_load()
{
string ClientIP = UtilityLibrary.Utilities.Network.GetClientIPAddress(HttpContext.Current.Request);
}

Where UtilityLibrary = Class Library
Utilities = Namespace
Network = Class Name

Bhavna81, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sankarmj@live.com
Sankarmj@live.com  
Posted on: 11/25/2011 4:20:26 AM
Level: Starter | Status: [Member] | Points: 25

UtilityLibrary = Class Library
Could send me the UtiUtilityLibrary dll and tell me the namespace?
its very urgent reply me ....
i'm facing the same problem.
Thanks Bhavna81..thanks for posting

Shankar.M
Think more... Code less

Bhavna81, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Vuyiswamb
Vuyiswamb  
Posted on: 11/25/2011 5:09:07 AM
Level: NotApplicable | Status: [Member] [MVP] [Administrator] | Points: 25

Bhavna81, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sankarmj@live.com
Sankarmj@live.com  
Posted on: 11/25/2011 5:36:12 AM
Level: Starter | Status: [Member] | Points: 25

@Vuyiswamb you mistaken i have added it....when i compile it shows me that UtilityLibrary doesn't exist in current context
what i have do further

Shankar.M
Think more... Code less

Bhavna81, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 10:38:51 AM