找人做网站应该注意什么,成都市企业网站建设,广州网络推广招聘,如何制作网站专题在前一次的项目中#xff0c;突然用到了这个获取本机的MAC地址#xff0c;然后就研究了一下#xff0c;记录下来#xff0c;防止以后再用到#xff0c; 使用winfrom做的#xff0c;界面一个button#xff0c;一个textBox,点了button以后给textBox赋值显示mac地址
附上源… 在前一次的项目中突然用到了这个获取本机的MAC地址然后就研究了一下记录下来防止以后再用到 使用winfrom做的界面一个button一个textBox,点了button以后给textBox赋值显示mac地址
附上源码 private void button3_Click(object sender, EventArgs e){try{string macAddress GetMacAddress();if (!string.IsNullOrEmpty(macAddress)){textBox1.Text macAddress;}else{MessageBox.Show(未能获取到MAC地址。, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error);}}catch (Exception ex){MessageBox.Show($获取MAC地址时出现错误{ex.Message}, 错误, MessageBoxButtons.OK, MessageBoxIcon.Error);}}private string GetMacAddress(){try{string macAddress string.Empty;foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()){/// 仅考虑以太网的网络接口if (nic.NetworkInterfaceType NetworkInterfaceType.Ethernet nic.OperationalStatus OperationalStatus.Up){// 获取网络接口的MAC地址macAddress nic.GetPhysicalAddress().ToString();// 将连续的十六进制数格式化为带冒号分隔符的形式macAddress FormatMacAddress(macAddress);if (!string.IsNullOrEmpty(macAddress))break;}}return macAddress;}catch (UnauthorizedAccessException){throw new Exception(没有足够的权限来访问网络接口信息请以管理员身份运行程序。);}catch (Exception ex){throw new Exception($获取MAC地址时出现错误{ex.Message});}}// 使用正则表达式将连续的十六进制数格式化为带冒号分隔符的形式private string FormatMacAddress(string macAddress){return Regex.Replace(macAddress, (.{2})(.{2})(.{2})(.{2})(.{2})(.{2}), $1:$2:$3:$4:$5:$6);}