【问题标题】:How to turn on Networked Computer by using WOL (Wake on Lan) C# or Java如何使用 WOL (Wake on Lan) C# 或 Java 打开联网计算机
【发布时间】:2011-10-15 19:10:19
【问题描述】:

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

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

【问题讨论】:

    标签: c# network-programming bios wake-on-lan netbios


    【解决方案1】:
    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 2020-12-16
      • 2012-02-01
      • 2013-08-06
      相关资源
      最近更新 更多