如何使用WOL(局域网唤醒)c#或Java打开联网计算机

本文关键字:Java 计算机 WOL 何使用 局域网 唤醒 | 更新日期: 2023-09-27 18:04:08

能否给我完整的代码,通过网卡和BIOS的WOL选项打开联网计算机

请提供我所有的细节,请尽量给我工作代码。

如何使用WOL(局域网唤醒)c#或Java打开联网计算机

using System;
using System.Net.Sockets;
//we derive our class from a standart one
public class WOLClass:UdpClient    
{
    public WOLClass():base()
    { }
    //this is needed to send broadcast packet
    public void SetClientToBrodcastMode()    
    {
      if(this.Active)
       this.Client.SetSocketOption(SocketOptionLevel.Socket,
                                 SocketOptionName.Broadcast,0);
    }
 }    
private void WakeFunction(string MAC_ADDRESS)   
     {
          WOLClass client=new WOLClass();
          client.Connect(new 
             IPAddress(0xffffffff),  //255.255.255.255  i.e broadcast
             0x2fff); // port=12287 let's use this one 
          client.SetClientToBrodcastMode();
          //set sending bites
          int counter=0;
          //buffer to be send
          byte[] bytes=new byte[1024];   // more than enough :-)
         //first 6 bytes should be 0xFF
         for(int y=0;y<6;y++)
            bytes[counter++]=0xFF;
         //now repeate MAC 16 times
         for(int y=0;y<16;y++)
         {
             int i=0;
             for(int z=0;z<6;z++)
             {
                  bytes[counter++]= 
                      byte.Parse(MAC_ADDRESS.Substring(i,2),
                      NumberStyles.HexNumber);
                  i+=2;
             }
         }
         //now send wake up packet
         int reterned_value=client.Send(bytes,1024);
     }

点击这里查看更多