tags:

views:

659

answers:

3

hello good fellas i'm trying to build some complicated stuff for an C# winform application being build online and trying to gather some information here and there.I've looked on the web that it's possible to get a mac address of a computer on the network using either System.Net.NetworkInformation or System.Management.ManagementClass(which i can't reference for some reasons).Where are my worries

1-Can my web server online know the mac address of a client's machine connected to it? 2- if question 1 is true i guess it will use IP(correct me if i'm wrong) what if client's machine is sitting behind a proxy server or using multiple web proxy? 3 if question 1 and 2 are positive How to do that from the web server

thanks for reading this

A: 

You can't get any of that information from a web server, and you should not try. Consider that machines may have multiple IP addresses and multiple MAC addresses, and may be behind a proxy server or Network Address Translation device, or worse.

IP addresses belong to the network layer, and should generally not be used by the Application layer. If nothing else, it's unlikely that the Network Administrators will consult the Developers when making changes to the network that will invalidate your assumptions.

John Saunders
+3  A: 

No, there's no easy way to do that.

The MAC address is only resolvable on the same subnet - assuming this isn't a fairly small intranet app, you would not be on the same subnet as your clients.

In theory, querying the client with remote WMI would work - but the firewall and permission issues are non-trivial. Again, unless you can control all clients - you're not likely to have success here.

About the only thing you could do is a downloadable app - possibly Flash, Silverlight or ActiveX - that interrogated the local machine for you. I'm not sure if that info would be sandboxed by the browser though.

My guess is there's an easier way to do what you're trying to do - but you'd need to provide more details on why you want the MAC address.

Mark Brackett
thanks for the reply.i think i'll have to build a small winform application to do that
black sensei
A: 

As the other responses suggest, getting the IP address may not do what you need. What are you trying to use this information for?

You might want to try and use the System.Management.ManagementObjectSearcher object to query for this kind of info. I know this can be used to grab the MAC address of each connected network adaptor. This logic would have to be on the client side that could then pass whatever info you needed up to the server.

It looks like this Google Groups post might do what you are after. Here is the interesting bit:

using System.Management;

ObjectQuery query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration"); 
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject mo in queryCollection )
{
     foreach(string s in addresses)
     { 
            Console.WriteLine( "IP Address ‘{0}’", s); 
     }
     foreach(string s in subnets)
     { 
            Console.WriteLine( "IP Subnet ‘{0}’", s); 
     }
}
auujay
i used the system.net.networkinformation namespace as i was saying.i've added the reference to the system.Management dll from the solution explorer (you know right click and click on add reference).but any time i use the namespace like using System.Management my reshaper intellisence underline it and says cannot resolve symbole.if i go ahead and build the project it fails.Don't know why.and this is the main reason i don't use the system.management.Oh yeah this is a school project that i take seriously to be proposed to Banks that covers certain aspect of ecommerce(security) can't say much :)
black sensei