How to get mac address of a client system in asp.net
-
Hi All. How to get mac address of a client system in asp.net?? I need to identify client system uniquely other than using IP address. If there is any other way for achieving the same please suggest... Thanks and Regards Mithun Narayanan.
-
Hi All. How to get mac address of a client system in asp.net?? I need to identify client system uniquely other than using IP address. If there is any other way for achieving the same please suggest... Thanks and Regards Mithun Narayanan.
And it involved this very issue. And a Senior MS Consultant (I hate to admit) showed me the path towards righteousness. Basically, your MAC address gets replaced with each frame along each router or some such non-sense. Meaning that outside your local network the MAC is meaningless. Much worse, some TCP/IP stacks do not even provide it through the API so you would need to really write some code to get it. http://tools.ietf.org/html/rfc1122[^] http://en.wikipedia.org/wiki/Ethernet[^]
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
Hi All. How to get mac address of a client system in asp.net?? I need to identify client system uniquely other than using IP address. If there is any other way for achieving the same please suggest... Thanks and Regards Mithun Narayanan.
In case of ASP.NET it is a client server architecture.. So you can only get things that are sent through request object. As every request is made by the browser (client) you can add the mac address to it and send it. So only option is your IP.... which is also the external one. :(
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NET -
Hi All. How to get mac address of a client system in asp.net?? I need to identify client system uniquely other than using IP address. If there is any other way for achieving the same please suggest... Thanks and Regards Mithun Narayanan.
Hi,try to do this. using System.Management; string stringMAC = ""; string stringIP = ""; ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration"); ManagementObjectCollection MOC= MC.GetInstances(); foreach(ManagementObject MO in MOC) { if ((bool)MO["IPEnabled"] == true) { stringMAC += MO["MACAddress"].ToString(); TextMAC.Text = stringMAC.ToString(); string[] IPAddresses = (string[]) MO["IPAddress"]; if(IPAddresses.Length > 0) stringIP = IPAddresses[0]; TextIP.Text = stringIP.ToString(); } }
April Comm100 - Leading Live Chat Software Provider
-
Hi All. How to get mac address of a client system in asp.net?? I need to identify client system uniquely other than using IP address. If there is any other way for achieving the same please suggest... Thanks and Regards Mithun Narayanan.
Hi, you can refer to the following code: [DllImport("Iphlpapi.dll")] private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); [DllImport("Ws2_32.dll")] private static extern Int32 inet_addr(string ip); private void Page_Load(object sender, System.EventArgs e) { // initial page try { string userip=Request.UserHostAddress; string strClientIP = Request.UserHostAddress.ToString().Trim(); Int32 ldest = inet_addr(strClientIP); //client ip Int32 lhost = inet_addr(""); //server ip Int64 macinfo = new Int64(); Int32 len = 6; int res = SendARP(ldest,0, ref macinfo, ref len); string mac_src=macinfo.ToString("X"); if(mac_src == "0") { if(userip=="127.0.0.1") Response.Write ("Localhost!"); else Response.Write ("welcome IP = " + userip + "<br>"); return; } while(mac_src.Length<12) { mac_src = mac_src.Insert(0,"0"); } string mac_dest=""; for(int i=0;i<11;i++) { if (0 == (i % 2)) { if ( i == 10 ) { mac_dest = mac_dest.Insert(0,mac_src.Substring(i,2)); } else { mac_dest ="-" + mac_dest.Insert(0,mac_src.Substring(i,2)); } } } Response.Write ("welcome IP = "+userip+ "<br>" + ",MAC = "+mac_dest + "<br>"); } catch(Exception err) { Response.Write(err.Message); } }
April Comm100 - Leading Live Chat Software Provider
-
In case of ASP.NET it is a client server architecture.. So you can only get things that are sent through request object. As every request is made by the browser (client) you can add the mac address to it and send it. So only option is your IP.... which is also the external one. :(
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NETSorry i cant use IP... if am using it i cant uniquly identify systems under a particular network... is ther any other way... i can it thru javascript but i ve to enable ActiveX which i dont want... :( is ther any other way.??
-
Hi,try to do this. using System.Management; string stringMAC = ""; string stringIP = ""; ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration"); ManagementObjectCollection MOC= MC.GetInstances(); foreach(ManagementObject MO in MOC) { if ((bool)MO["IPEnabled"] == true) { stringMAC += MO["MACAddress"].ToString(); TextMAC.Text = stringMAC.ToString(); string[] IPAddresses = (string[]) MO["IPAddress"]; if(IPAddresses.Length > 0) stringIP = IPAddresses[0]; TextIP.Text = stringIP.ToString(); } }
April Comm100 - Leading Live Chat Software Provider
Thank u for the response.. i ll try this nd revert ..
-
Hi, you can refer to the following code: [DllImport("Iphlpapi.dll")] private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); [DllImport("Ws2_32.dll")] private static extern Int32 inet_addr(string ip); private void Page_Load(object sender, System.EventArgs e) { // initial page try { string userip=Request.UserHostAddress; string strClientIP = Request.UserHostAddress.ToString().Trim(); Int32 ldest = inet_addr(strClientIP); //client ip Int32 lhost = inet_addr(""); //server ip Int64 macinfo = new Int64(); Int32 len = 6; int res = SendARP(ldest,0, ref macinfo, ref len); string mac_src=macinfo.ToString("X"); if(mac_src == "0") { if(userip=="127.0.0.1") Response.Write ("Localhost!"); else Response.Write ("welcome IP = " + userip + "<br>"); return; } while(mac_src.Length<12) { mac_src = mac_src.Insert(0,"0"); } string mac_dest=""; for(int i=0;i<11;i++) { if (0 == (i % 2)) { if ( i == 10 ) { mac_dest = mac_dest.Insert(0,mac_src.Substring(i,2)); } else { mac_dest ="-" + mac_dest.Insert(0,mac_src.Substring(i,2)); } } } Response.Write ("welcome IP = "+userip+ "<br>" + ",MAC = "+mac_dest + "<br>"); } catch(Exception err) { Response.Write(err.Message); } }
April Comm100 - Leading Live Chat Software Provider
Thank u for the response..
-
Thank u for the response.. i ll try this nd revert ..
ha ha ... this will give you the Mac address of the Server. .. :laugh:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NET -
ha ha ... this will give you the Mac address of the Server. .. :laugh:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Windows7 API Code Pack
Simplify Code Using NDepend
Basics of Bing Search API using .NETi knw tat... i ve tried it long back ago...