简体   繁体   English

Mono在Debian错误CS0234上

[英]Mono on debian error CS0234

I have a debian server and i saved its mac address on a txt file in the /usr folder. 我有一个Debian服务器,我上的/ usr文件夹中的txt文件保存它的MAC地址。

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. 每次启动计算机时,我要执行的脚本都应检查当前的mac地址并将其与txt文件中保存的地址进行比较。 If they don't match than the machine should shutdown. 如果它们不匹配,则机器应关闭。

The code works on Windows , but i have to make it work on debian. 该代码可在Windows上运行,但我必须使其在debian上运行。 So i installed mono (apt-get install mono-complete) ,created the .cs file containing the code and transferred it on debian machine. 所以我安装了mono(apt-get install mono-complete),创建了包含代码的.cs文件,并将其传输到debian机器上。

When i run the mcs shutdown.cs (shutdown is the name of the file i created) command i get this error : 当我运行MCS shutdown.cs(关机是我创建的文件名)命令我得到这个错误:

CS0234: The type or namespace name 'NetworkInformation' does not exist i the namespace 'System.Net'. CS0234:在名称空间“ System.Net”中,类型或名称空间名称“ NetworkInformation”不存在。 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 . System.Net.NetworkInformation.NetworkInterface类根据以下内容位于System.dll中: http : //msdn.microsoft.com/zh-cn/library/system.net.networkinformation.networkinterface Did you try adding a reference to System.dll when compiling? 编译时是否尝试添加对System.dll的引用? I believe it's the "-r" argument to mcs. 我相信这是mcs的“ -r”参数。

BTW, what version of Mono are you using. 顺便说一句,您正在使用哪个版本的Mono。 Debian is famous for shipping very old versions of Mono in the "stable" flavour. Debian以“稳定”的味道运送非常老版本的Mono而闻名。 Mono 2.10.x or higher is recommended, nowadays, as stable. 如今,建议使用Mono 2.10.x或更高版本。

System.Net.NetworkInformation.NetworkInterface was introduced .NET 2.0. .NET 2.0引入了System.Net.NetworkInformation.NetworkInterface。 You need to target .NET 2.0 profile or newer if you want to use it. 如果要使用.NET 2.0配置文件,则需要使用它。

If you are compiling using command line compiler use gmcs or dmcs to compile your project. 如果使用命令行编译器进行编译,请使用gmcs或dmcs来编译项目。 If you are using MonoDevelop you need to set in project setting appropriate framework version. 如果您使用的是MonoDevelop,则需要在项目中设置适当的框架版本。

This is how you might do this in Ruby. 这就是您可能在Ruby中执行的操作。

begin
  theMac = File.read("/usr/path/to/text/file.txt")

rescue Exception => e
  puts e.message
  puts e.backtrace.inspect
end

response = `ifconfig eth0`
mac = response.match(/HWaddr (.*?):(.*?):(.*?):(.*?):(.*?):(.*?) /)

if theMac == mac[0] then `sudo shutdown -h now`; end

f = File.open("/usr/path/to/text/file.txt", "w")
f.write(mac[0])
f.close()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VS 2015 CS0234错误错误 - VS 2015 CS0234 False Error 错误CS0234名称空间名称'编码'不存在 - ERROR CS0234 namespace name 'Encodings' does not exist CS0234运行时错误,对于同一程序集中的类 - CS0234 Error on runtime, for classes in the same assembly 运行赛车游戏演示时出现错误CS0234 - Error CS0234 When Running Racing Game Demo CS0234用于引用的本地项目 - CS0234 for Referenced Local Project 运行浏览器自动化时 UIPath 出错:System.ArgumentException:没有编译代码运行错误 CS0234: - Error in UIPath while running a browser automation : System.ArgumentException: No compiled code to run error CS0234: 错误 CS0234 命名空间“Xamarin.Forms.Platform”中不存在类型或命名空间名称“Android” - Error CS0234 The type or namespace name 'Android' does not exist in the namespace 'Xamarin.Forms.Platform 错误 CS0234 命名空间“Microsoft”中不存在类型或命名空间名称“Reporting”(您是否缺少程序集引用?) - Error CS0234 The type or namespace name 'Reporting' does not exist in the namespace 'Microsoft' (Are you missing an assembly reference?) 错误CS0234:名称空间“System.Runtime.InteropServices”中不存在类型或命名空间名称“CustomMarshalers” - Error CS0234: The type or namespace name 'CustomMarshalers' does not exist in the namespace 'System.Runtime.InteropServices' 错误CS0234类型或名称空间名称'SendTextMessageAsync'在名称空间'Telegram.Bot'中不存在 - Error CS0234 The type or namespace name 'SendTextMessageAsync' does not exist in the namespace 'Telegram.Bot'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM