网卡唤醒电脑
进入BIOS一般会发现有网卡唤醒、PCI调制解调器唤醒、串口Ring唤醒和时钟唤醒。一般用户的定时开机需求由时钟唤醒即可解决,不过若是想要在外地也可以轻松打开自己的电脑,网卡唤醒可以解决这个问题。
网卡唤醒只需要两个参数:广播地址和MAC地址。如果是内网网卡唤醒则只需要MAC地址,广播地址是255.255.255.255。但是怎么知道外网ip的广播地址呢,广播地址等于子网按位求反和IP地址的或运算。

public static string GetBroadcast(IPAddress ipAddress, IPAddress subnetMask) { byte[] ip = ipAddress.GetAddressBytes(); byte[] sub = subnetMask.GetAddressBytes(); for (int i = 0; i < ip.Length; i++) { ip[i] = (byte) ((~sub[i]) | ip[i]); //广播地址=子网按位求反 或 IP地址 } return new IPAddress(ip).ToString(); }
至此就只需要知道发什么给需要被唤醒的电脑了,MAC魔术封包可以实现网卡唤醒

/// <summary> /// 字符串转16进制字节数组 /// </summary> /// <param name="hexStr"></param> /// <returns></returns> public static byte[] StrToHexByte(string hexStr) { hexStr = hexStr.Replace(" ", "").Replace("-", "").Replace(":", ""); if ((hexStr.Length%2) != 0) hexStr += " "; byte[] returnBytes = new byte[hexStr.Length/2]; for (int i = 0; i < returnBytes.Length; i++) returnBytes[i] = Convert.ToByte(hexStr.Substring(i*2, 2), 16); return returnBytes; } /// <summary> /// 拼装MAC魔术封包 /// </summary> /// <param name="macStr"></param> /// <returns></returns> public static byte[] GetMagicPacket(string macStr) { byte[] returnBytes = new byte[102]; const string commandStr = "FFFFFFFFFFFF"; for (int i = 0; i < 6; i++) returnBytes[i] = Convert.ToByte(commandStr.Substring(i*2, 2), 16); byte[] macBytes = StrToHexByte(macStr); for (int i = 6; i < 102; i++) { returnBytes[i] = macBytes[i%6]; } return returnBytes; }
另外附上IP转MAC的方法,不过需要在该电脑开启的情况下才能获取它的MAC地址。
此网卡唤醒做了一个Winform界面的程序,一个控制台的程序,控制台程序由bat文件批量唤醒电脑

@echo off start D:\NetworkCardWake.exe 00-E0-4C-68-08-E7 183.233.129.53 183.233.129.1
本程序有参考其他人的博客,完整程序
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!