C# WPF 怎么把mac地址保存在exe内部
你可以使用以下代码来获取并保存Mac地址到exe内部:
using System;
using System.IO;
using System.Net.NetworkInformation;
using System.Windows;
namespace YourNamespace
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string macAddress = GetMacAddress();
// 保存Mac地址到exe内部
File.WriteAllText("mac.txt", macAddress);
}
private string GetMacAddress()
{
string macAddress = "";
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddress = nic.GetPhysicalAddress().ToString();
break;
}
}
return macAddress;
}
}
}
这段代码首先使用NetworkInterface.GetAllNetworkInterfaces()方法来获取所有的网络接口,然后通过遍历每个网络接口,找到处于操作状态的接口,并获取其物理地址(Mac地址)。最后使用File.WriteAllText()方法将Mac地址保存到名为"mac.txt"的文本文件中。请确保在保存之前,你已经获取到了正确的Mac地址
原文地址: https://www.cveoy.top/t/topic/hLlM 著作权归作者所有。请勿转载和采集!