C# C-仅在选定的mac地址上运行我的程序
我在我的项目中使用C,我只想在选定的计算机上运行,我们使用mac地址检查计算机mac地址是否在列表中,如果不在列表中,则显示类似的消息 如何使用C实现这一点C# C-仅在选定的mac地址上运行我的程序,c#,mac-address,C#,Mac Address,我在我的项目中使用C,我只想在选定的计算机上运行,我们使用mac地址检查计算机mac地址是否在列表中,如果不在列表中,则显示类似的消息 如何使用C实现这一点 if (listofmacaddress == true) { //run the program } else { MessageBox.Show("Invalid mac address, application close. ", "Error",
if (listofmacaddress == true)
{
//run the program
}
else
{
MessageBox.Show("Invalid mac address, application close. ",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
public static bool listofmacaddress()
{
var mac = // get mac address
if(mac == "##########1")
return true;
else if(mac == "#########2")
return true;
else
return false;
}
大概是这样的:
public string GetMACAddress()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
string macAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (macAddress == String.Empty)
{
var properties = adapter.GetIPProperties();
macAddress = adapter.GetPhysicalAddress().ToString();
}
} return macAddress;
}
它必须是一个函数,用于检查pc macaddress是否在列表中,如果找到mac address,则返回true或false类似的内容。@KenWhite不,不是。是的,是;我会读书。您所问的问题被提取到代码的一行,即var mac=//get mac address,该问题回答了这个问题。如果你有一个不同的问题,那就换个问题问。既定的目标似乎很愚蠢。这将在具有具有特定MAC地址的NIC的机器上运行,因此只需将NIC移动到要在其中运行程序的机器上,或者创建虚拟机,并将MAC设置为已知值,可以在Linux中使用strings命令从二进制文件中检索该值。再次阅读我的最后评论,具体解决了这里已经存在的关于这个主题的问题。你在看我写的东西吗?使用硬件标识的想法行不通。必须更换硬件,否则可能会被欺骗。这已经在这里讨论过几十个问题了。搜索唯一标识的硬件,看看为什么这是个坏主意。不要指望我们在这里为你搜索。这个问题是关于识别MAC地址的,它是我链接的帖子的副本。