Hi,
I'm kind of new to .Net coding and I'm trying to write a script that will output to a webpage the MAC Address of the computer accessing this page, and I keep getting that compilation error here's the error
Compiler Error Message: CS0234: The type or namespace name 'Management'
does not exist in the namespace 'System' (are you missing an assembly
reference?)
here's my cs code:
1 using System;
2 using System.Text;
3 using System.Runtime.InteropServices;
4 using System.Management;
5
6 public class GetInfo
7 {
8
9 public string GetMACAddress()
10 {
11 ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
12 ManagementObjectCollection moc = mc.GetInstances();
13 string MACAddress=String.Empty;
14 foreach(ManagementObject mo in moc)
15 {
16 if(MACAddress==String.Empty) // only return MAC Address from first card
17 {
18 if((bool)mo["IPEnabled"] == true) MACAddress= mo["MacAddress"].ToString() ;
19 }
20 mo.Dispose();
21 }
22 MACAddress=MACAddress.Replace(":","");
23 return MACAddress;
24 }
25 }
26
and here's aspx page code:
<%@ page Language="C#" Inherits="GetInfo" src="macaddress.cs" %>
<script runat="server">
void return_mac_address (Object sender, EventArgs e)
{
GetInfo MyMac=new GetInfo();
string sMac = MyMac.getMACAddress();
result.Text= sMac;
}
void Page_Load (Object sender, EventArgs e)
{
if (!Page.IsPostBack) {
return_mac_address();
}
}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<br />
<asp:Label id="result" runat="Server"></asp:Label>
</select>
</form>
</body>
</html>
Can anoby help me with this please.
Thanks a lot.