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

发布于 2024-11-27 02:08:05 字数 75 浏览 1 评论 0原文

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

请向我提供所有详细信息,并尝试给我工作代码。

Can u please give me full code to turn on networked computer by WOL option of Network Card and BIOS.

Please provide me all the details and please try to give me working code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-12-04 02:08:05
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);
     }

在此处查看更多内容

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);
     }

See more here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文