I have a debian server and i saved its mac address on a txt file in the /usr folder.
Every time i start the machine the script i’m trying to do should check the current mac address and compare it to the one saved on the txt file. If they don’t match than the machine should shutdown.
The code works on Windows , but i have to make it work on debian. So i installed mono (apt-get install mono-complete) ,created the .cs file containing the code and transferred it on debian machine.
When i run the mcs shutdown.cs (shutdown is the name of the file i created) command i get this error :
CS0234: The type or namespace name ‘NetworkInformation’ does not exist i the namespace ‘System.Net’. Are you missing an assembly reference?**
How can this be solved?
using System.Net.NetworkInformation;
static void Main(string[] args)
{
string newmc = Convert.ToString(GetMacAddress()); //current mac address
string mc = File.ReadAllText(@"/usr/mc.txt"); //mac address saved on a txt file previously
if (newmc != mc) //shutdown if the mac addresses dont match
{
System.Diagnostics.Process.Start("shutdown.exe", "-s -t 0");
}
}
static string GetMacAddress()
{
string macAddresses = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue;
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress().ToString();
break;
}
}
return macAddresses;
}
System.Net.NetworkInformation.NetworkInterface class is in System.dll according to this: http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface . Did you try adding a reference to System.dll when compiling? I believe it’s the “-r” argument to mcs.
BTW, what version of Mono are you using. Debian is famous for shipping very old versions of Mono in the “stable” flavour. Mono 2.10.x or higher is recommended, nowadays, as stable.