基本信息
源码名称:C# 远程唤醒计算机(幻数据包唤醒计算机)
源码大小:0.05M
文件格式:.rar
开发语言:C#
更新时间:2018-07-11
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
一.定义
网络唤醒:唤醒休眠状态下的计算机,而不是已关机的计算机。
优势:可通过定时功能实现自动唤醒计算机,减少人力使用。
实现方法:通过被唤醒机的MAC地址进行广播发送请求,唤醒计算机。
二.硬件设置
1.Win7系统下设置如下图,计算机-》设备管理器-》网卡驱动属性
2.在BIOS设置允许网络唤醒
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication12
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
//通过正则表达式设定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 MainWindow()
{
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)
{
//发送方法是通过UDP
UdpClient client = new UdpClient();
//Broadcast内容为:255,255,255,255.广播形式,所以不需要IP
client.Connect(System.Net.IPAddress.Broadcast, 50000);
//下方为发送内容的编制,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转换成byte
for (var i = 0; i < 6; i )
{
var byteValue = Convert.ToByte(sArray[i], 16);
mac[i] = byteValue;
}
return mac;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
WakeUp("00-01-80-7E-C3-D2");
}
}
}