一、需求

1、人在公司坐,昨晚写的文档放在家中电脑忘记Copy了,想要访问家中电脑拿到文档。

2、家中或公司中局域网内有某台电脑(或服务器)要开机,或者批量一键打开局域网内某些电脑

二、必备条件

1、网线连接电脑网口(wifi无线网卡无法网络唤醒)

2、网卡支持网络唤醒功能

三、设置

1、主板BIOS设置

目前测试过的主板:微星PRO Z690-A WIFI DDR4(MS-7D25)、技嘉B75M-D3V、技嘉B85M-D2V

下面以微星PRO Z690-A为例。

主板:微星PRO Z690-A WIFI DDR4

系统:Windows10

路由器:中兴AX5400,TPLink5600和7660

发包程序:C#,下面有源码,或者伸手党可以直接从下载链接获取发布好的应用程序

开机狂按Del键进入微星BIOS,其他品牌DEL, ESC, F1, F2, F8, F9, F10, F12

  1. 高级–整合周边设备–网卡ROM启动,设置为允许
  2. 高级–电源管理设置–Eup 2013,设置为禁止
  3. 高级–唤醒事件设置–PCIE设备唤醒,设置为允许

2、网卡(Windows)设置

  1. 控制面板–所有控制面板项–网络连接
  2. 在网卡适配器点击鼠标右键–属性,弹出的属性对话框中
  3. 选择网络选项卡–配置
  4. 选择高级选项卡,将关机 网络唤醒设置为开启,将魔术封包唤醒设置为开启
  5. 电源管理选项卡,勾选下面三个选项,允许此设备唤醒计算机。
  6. 切换为电源管理选项,勾选允许此设备唤醒计算机。
  7. 关闭快速启动,右击开始按钮,点击“电源选项”,点击“选择电源按钮的功能”;点击“更改当前不可用的设置”,把“启用快速启动”勾选。(这条必须做)

3、后记

  1. 电脑网线连接网口处,电脑关机状态下有的会有黄灯常量,有的电脑不亮,都能唤醒
  2. 在设置网卡的时候发现没有关机 网络唤醒的选项的时候,有可能是网卡驱动或者网卡版本不同,没有此选项也能唤醒。

三、C#源码

伸手党可以直接从下载链接获取发布好的应用程序,下载地址:

https://download.csdn.net/download/hwt0101/86781647

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;namespace RemotePowerOn
{public partial class Form1 : Form{//通过正则表达式设定MAC地址筛选标准,关于正则表达式请自行百度const string macCheckRegexString = @"^([0-9a-fA-F]{2})(([/\s:-][0-9a-fA-F]{2}){5})$";private static readonly Regex MacCheckRegex = new Regex(macCheckRegexString);public Form1(){InitializeComponent();}public static bool WakeUp(string mac){//查看该MAC地址是否匹配正则表达式定义,(mac,0)前一个参数是指mac地址,后一个是从指定位置开始查询,0即从头开始if (MacCheckRegex.IsMatch(mac, 0)){byte[] macByte = FormatMac(mac);WakeUpCore(macByte);return true;}return false;}private static void WakeUpCore(byte[] mac){//发送方法是通过UDPUdpClient client = new UdpClient();//Broadcast内容为:255,255,255,255.广播形式,所以不需要IPclient.Connect(System.Net.IPAddress.Broadcast, 40000);//下方为发送内容的编制,6遍“FF”+17遍mac的byte类型字节。byte[] packet = new byte[17 * 6];for (int i = 0; i < 6; i++)packet[i] = 0xFF;for (int i = 1; i <= 16; i++)for (int j = 0; j < 6; j++)packet[i * 6 + j] = mac[j];//唤醒动作int result = client.Send(packet, packet.Length);}private static byte[] FormatMac(string macInput){byte[] mac = new byte[6];string str = macInput;//消除MAC地址中的“-”符号string[] sArray = str.Split('-');//mac地址从string转换成bytefor (var i = 0; i < 6; i++){var byteValue = Convert.ToByte(sArray[i], 16);mac[i] = byteValue;}return mac;}private void button1_Click(object sender, EventArgs e){string mac = textBox1.Text;WakeUp(mac);//WakeUp("25-D5-47-12-97-E2"); }private void button2_Click(object sender, EventArgs e){#region 方法1// TODO: Implement Functionality Here// Get my PC IP addressMsg(string.Format("My IP : {0}", GetIPAddress()));// Get My PC MAC addressMsg(string.Format("My MAC: {0}", GetMacAddress()));// Get My PC HostNameMsg(string.Format("My HostName: {0}", Dns.GetHostName()));// Get all devices on networkDictionary<IPAddress, PhysicalAddress> all = GetAllDevicesOnLAN();foreach (KeyValuePair<IPAddress, PhysicalAddress> kvp in all){Msg(string.Format("IP : {0}\n MAC {1}", kvp.Key, kvp.Value));}#endregion#region 方法2//GetIPAddress2();//foreach (var ip in ips)//{//    //Console.WriteLine(ip);//    Msg(ip);//}#endregion}#region MAC扫描方法1//public static void Main(string[] args)//{// Console.WriteLine("Hello World!");//  // TODO: Implement Functionality Here// // Get my PC IP address//   Console.WriteLine("My IP : {0}", GetIPAddress());//   // Get My PC MAC address//  Console.WriteLine("My MAC: {0}", GetMacAddress());//  // Get My PC HostName// Console.WriteLine("My HostName: {0}", Dns.GetHostName());//    // Get all devices on network// Dictionary<IPAddress, PhysicalAddress> all = GetAllDevicesOnLAN();// foreach (KeyValuePair<IPAddress, PhysicalAddress> kvp in all)//   {//     Console.WriteLine("IP : {0}\n MAC {1}", kvp.Key, kvp.Value);//    }// Console.Write("Press any key to continue . . . ");//  Console.ReadKey(true);//}/// <summary>/// MIB_IPNETROW structure returned by GetIpNetTable/// DO NOT MODIFY THIS STRUCTURE./// </summary>[StructLayout(LayoutKind.Sequential)]struct MIB_IPNETROW{[MarshalAs(UnmanagedType.U4)]public int dwIndex;[MarshalAs(UnmanagedType.U4)]public int dwPhysAddrLen;[MarshalAs(UnmanagedType.U1)]public byte mac0;[MarshalAs(UnmanagedType.U1)]public byte mac1;[MarshalAs(UnmanagedType.U1)]public byte mac2;[MarshalAs(UnmanagedType.U1)]public byte mac3;[MarshalAs(UnmanagedType.U1)]public byte mac4;[MarshalAs(UnmanagedType.U1)]public byte mac5;[MarshalAs(UnmanagedType.U1)]public byte mac6;[MarshalAs(UnmanagedType.U1)]public byte mac7;[MarshalAs(UnmanagedType.U4)]public int dwAddr;[MarshalAs(UnmanagedType.U4)]public int dwType;}/// <summary>/// GetIpNetTable external method/// </summary>/// <param name="pIpNetTable"></param>/// <param name="pdwSize"></param>/// <param name="bOrder"></param>/// <returns></returns>[DllImport("IpHlpApi.dll")][return: MarshalAs(UnmanagedType.U4)]static extern int GetIpNetTable(IntPtr pIpNetTable,[MarshalAs(UnmanagedType.U4)] ref int pdwSize, bool bOrder);/// <summary>/// Error codes GetIpNetTable returns that we recognise/// </summary>const int ERROR_INSUFFICIENT_BUFFER = 122;/// <summary>/// Get the IP and MAC addresses of all known devices on the LAN/// </summary>/// <remarks>/// 1) This table is not updated often - it can take some human-scale time///    to notice that a device has dropped off the network, or a new device///    has connected./// 2) This discards non-local devices if they are found - these are multicast///    and can be discarded by IP address range./// </remarks>/// <returns></returns>private static Dictionary<IPAddress, PhysicalAddress> GetAllDevicesOnLAN(){Dictionary<IPAddress, PhysicalAddress> all = new Dictionary<IPAddress, PhysicalAddress>();// Add this PC to the list...all.Add(GetIPAddress(), GetMacAddress());int spaceForNetTable = 0;// Get the space needed// We do that by requesting the table, but not giving any space at all.// The return value will tell us how much we actually need.GetIpNetTable(IntPtr.Zero, ref spaceForNetTable, false);// Allocate the space// We use a try-finally block to ensure release.IntPtr rawTable = IntPtr.Zero;try{rawTable = Marshal.AllocCoTaskMem(spaceForNetTable);// Get the actual dataint errorCode = GetIpNetTable(rawTable, ref spaceForNetTable, false);if (errorCode != 0){// Failed for some reason - can do no more here.throw new Exception(string.Format("Unable to retrieve network table. Error code {0}", errorCode));}// Get the rows countint rowsCount = Marshal.ReadInt32(rawTable);IntPtr currentBuffer = new IntPtr(rawTable.ToInt64() + Marshal.SizeOf(typeof(Int32)));// Convert the raw table to individual entriesMIB_IPNETROW[] rows = new MIB_IPNETROW[rowsCount];for (int index = 0; index < rowsCount; index++){rows[index] = (MIB_IPNETROW)Marshal.PtrToStructure(new IntPtr(currentBuffer.ToInt64() +(index * Marshal.SizeOf(typeof(MIB_IPNETROW)))),typeof(MIB_IPNETROW));}// Define the dummy entries list (we can discard these)PhysicalAddress virtualMAC = new PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });PhysicalAddress broadcastMAC = new PhysicalAddress(new byte[] { 255, 255, 255, 255, 255, 255 });foreach (MIB_IPNETROW row in rows){IPAddress ip = new IPAddress(BitConverter.GetBytes(row.dwAddr));byte[] rawMAC = new byte[] { row.mac0, row.mac1, row.mac2, row.mac3, row.mac4, row.mac5 };PhysicalAddress pa = new PhysicalAddress(rawMAC);if (!pa.Equals(virtualMAC) && !pa.Equals(broadcastMAC) && !IsMulticast(ip)){//Console.WriteLine("IP: {0}\t\tMAC: {1}", ip.ToString(), pa.ToString());if (!all.ContainsKey(ip)){all.Add(ip, pa);}}}}finally{// Release the memory.Marshal.FreeCoTaskMem(rawTable);}return all;}/// <summary>/// Gets the IP address of the current PC/// </summary>/// <returns></returns>private static IPAddress GetIPAddress(){String strHostName = Dns.GetHostName();IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);IPAddress[] addr = ipEntry.AddressList;foreach (IPAddress ip in addr){if (!ip.IsIPv6LinkLocal){return (ip);}}return addr.Length > 0 ? addr[0] : null;}/// <summary>/// Gets the MAC address of the current PC./// </summary>/// <returns></returns>private static PhysicalAddress GetMacAddress(){foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()){// Only consider Ethernet network interfacesif (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&nic.OperationalStatus == OperationalStatus.Up){return nic.GetPhysicalAddress();}}return null;}/// <summary>/// Returns true if the specified IP address is a multicast address/// </summary>/// <param name="ip"></param>/// <returns></returns>private static bool IsMulticast(IPAddress ip){bool result = true;if (!ip.IsIPv6Multicast){byte highIP = ip.GetAddressBytes()[0];if (highIP < 224 || highIP > 239){result = false;}}return result;}#endregion#region MAC扫描方法2static List<string> ips = new List<string>();static Dictionary<string, string> dic1 = new Dictionary<string, string>();static void GetIPAddress2(){string myHostName = Dns.GetHostName();//本机名string myHostIP = Dns.GetHostEntry(myHostName).AddressList[1].ToString();//本机IP地址string IpRange = myHostIP.Remove(myHostIP.LastIndexOf('.'));//IP网段for (int r = 1; r <= 255; r++)//枚举网段计算机{Ping ping = new Ping();ping.PingCompleted += new PingCompletedEventHandler(ping_Completed);//事件绑定方法string pingIP = IpRange + "." + r.ToString();ping.SendAsync(pingIP, 1000, null);}}static void ping_Completed(object sender, PingCompletedEventArgs e){if (e.Reply.Status == IPStatus.Success){ips.Add(e.Reply.Address.ToString());if (!dic1.ContainsKey(e.Reply.Address.ToString())){dic1[e.Reply.Address.ToString()] = "";}}}#endregionprivate void Msg(string e){try{string msg = "";//if (string.IsNullOrEmpty(richTextBox1.Text))//{//    msg = e;//}//else//{//    msg = richTextBox1.Text + "\r\n" + e;//}msg = e;if (base.InvokeRequired){base.Invoke(new MethodInvoker(() =>{richTextBox1.Text = richTextBox1.Text + "\r\n" + e;}));}else{richTextBox1.Text = richTextBox1.Text + "\r\n" + e;}}catch{}}}
}

四、 外网远程唤醒方案

  1. 家中放一台微型迷你低功耗计算机或者网关(树莓派、网关、迷你服务器)功耗在10W左右,保持24小时常开,一年电费在一百左右。安装向日葵或者ToDesk设置无人值守,支持电脑和手机App连接。随时随地连接到桌面后,用远程发包软件(文中源码或直接下载打包程序)来远程网络唤醒局域网内其他电脑。
  2. 使用向日葵开机棒,参照官方设置即可,主要是开机棒开放了mac地址开机。可以使得开机棒不局限于一台计算机开机了。在向日葵的网站上找到开机棒,或者在手机就app中找到,然后输入mac地址,即可。
  3. 使用路由器(例如TP-Link)自带的域名解析功能,参考文章:【超详细】Windows设置远程唤醒WOL+远程连接(远程开机)_wyouzhi@yyds的博客-CSDN博客_远程开机与远程唤醒bios设置

c# 远程网络唤醒电脑(电脑远程开机+内网MAC和IP扫描)(附带源码+主板和Windows开启详细说明+外网远程唤醒方案)相关推荐

  1. 计算机毕业设计ssmJava网名推荐系统5j37v系统+程序+源码+lw+远程部署

    计算机毕业设计ssmJava网名推荐系统5j37v系统+程序+源码+lw+远程部署 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 开发软件:idea eclipse 前端技术:Layu ...

  2. [附源码]计算机毕业设计Python+uniapp基于Android的网店系统i7581(程序+源码+LW+远程部署)

    [附源码]计算机毕业设计Python+uniapp基于Android的网店系统i7581(程序+源码+LW+远程部署) 该项目含有源码.文档.程序.数据库.配套开发软件.软件安装教程 项目运行环境配置 ...

  3. 用python求解:用户分别输入外援半径和内圆半径,计算圆环的面积;及用户分别输入圆柱的底面圆半径和高,输出圆柱和表面积。(附带源码)

    用python求解:用户分别输入外援半径和内圆半径,计算圆环的面积:及用户分别输入圆柱的底面圆半径和高,输出圆柱和表面积.(附带源码) 纯分享一下平时练习题: 运算结果如下 源代码如下: import ...

  4. 乐鑫Esp32学习之旅28 安信可 ESP32-Cam 摄像头开发板二次开发 C SDK编程,实现MQTT远程拍照传输到私有服务器。(附带源码)

    本系列博客学习由非官方人员 半颗心脏 潜心所力所写,仅仅做个人技术交流分享,不做任何商业用途.如有不对之处,请留言,本人及时更改. 1. 爬坑学习新旅程,虚拟机搭建esp32开发环境,打印 " ...

  5. 3.3 利用群晖:群辉与PC电脑直连,实现万兆/2.5G速度文件互传(解决 直连后 网络/外网/网页 访问变慢,直连后群辉无网络 cloud sync无网络)

    为黑群晖和电脑装备了万兆X540 T2网卡,为实现万兆速度的文件互传,决定将黑群晖直连PC,其需要注意的点有以下三点: 修改PC和群辉的IPv4: 为实现固定IP访问群辉,这里建议修改PC和群辉均为固 ...

  6. 多IP服务器自动切换内网IP易语言源码

    介绍: 自动切换电脑内网IP, 记得以前开发这个主要是适应国外多IP服务器切换,对一般用户 用处不大. 所以把源码代码发出来 可以根据自己需求修改了或者学习一下. 网盘下载地址: http://kek ...

  7. PyQT5学习之旅 1 如何自定义控件,入门做一个上位电脑串口调试软件,全部开源。(附带源码)

    文章目录 一.前言 二.开发的必备工具 2.1 PyCharm 如何集成 QT Designer UI代码转可视化 可视转化UI代码 打包成 exe 软件: 2.2.引进自定义控件 移除此控件为自定义 ...

  8. VC++获取电脑的各个磁盘盘符及容量信息(附源码)

    目录 1.调用GetLogicalDrives接口获取逻辑磁盘个数 2.调用GetLogicalDriveStrings接口获取磁盘盘符列表字串

  9. 【Vue框架】Vue绑定样式及案例之行内样式——对象绑定样式与数组控制样式(附带源码案例)

    文章目录 一.Vue样式绑定 1.1 Vue绑定class样式 1.2 Vue绑定行内样式 1.2.1 对象控制绑定样式 1.2.2 数组控制绑定样式 1.3 Vue绑定样式案例(标题排他) 1.4 ...

最新文章

  1. 阿里OceanBase GitHub点赞送礼引争议,CTO道歉,贾扬清、李沐讨论开源刷Star
  2. 今天看到一个关于营销学和广告创意研究的文章
  3. php oracle创建临时表,Oracle常用命令笔记
  4. 白话Elasticsearch69-ES生产集群部署重要的 Elasticsearch参数设置
  5. 用鸿蒙跑了个 hello world
  6. python微服务监控_如何用zabbix监控微服务
  7. debian/ubuntu19.10下安装使用护眼软件f.lux
  8. leetcode186. 翻转字符串里的单词 II
  9. 项目管理杂谈-员工的积极性在哪里?
  10. 《数源思维》提问工具之“语法套”
  11. 201906017学习小程序
  12. android按钮点击后闪退_iphone闪退是什么原因?
  13. 《Java8实战》读书笔记
  14. IT负载率与数据中心规模——孙长青
  15. 市场需求上升,网络安全硬件平台行业逐渐占据主导地位
  16. Win10 + Ubuntu20.04 双系统+双硬盘安装
  17. mybatis用注解实现 一对一,一对多,多对多哟
  18. GTD时间管理学习心得(1)
  19. C语言之:数组的定义和初始化必备练习题
  20. Drools基础语法

热门文章

  1. 1000卡路里计算器_Excel卡路里燃烧计算器
  2. VB全面控制Excel方法大汇总
  3. @value值获取不到配置文件值
  4. 网易云的特色与优势?|网易云
  5. Android的计量单位px,in,mm,pt,dp,dip,sp
  6. Python爬虫下载视频(梨视频)
  7. 将数据库转换为word文档
  8. Linux 用户文件夹授权
  9. VB6不能加载MSCOMCTL.OCX最简单的解决办法
  10. JAVA大数据需要学什么