从原始 Windows cmd 执行网络唤醒?

从原始 Windows cmd 执行网络唤醒?

有没有一种方法可以在不使用任何额外工具的情况下,使用 Windows 命令行触发位于同一本地网络上的已启用计算机上的局域网唤醒?到目前为止,我发现的所有方法都需要安装一个额外的程序 - 但 WOL 只需要将特定程序包发送到特定的 MAC 地址,所以我认为这应该可以使用 telnet 或 vanilla windows 上可用的其他工具来实现?

//编辑:我不明白为什么这个问题被关闭了?我特别不是在寻找应用程序,而是在寻找一种使用原始 Windows 实现 WOL 的方法。

答案1

如果您只想使用内置的 Windows 工具,请参阅 powershell.one 文章 网络唤醒 包含一个 PowerShell 函数,可用于向 MAC 地址发出 LAN 唤醒包。

该脚本在此处重复:

function Invoke-WakeOnLan
{
  param
  (
    # one or more MACAddresses
    [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
    # mac address must be a following this regex pattern:
    [ValidatePattern('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$')]
    [string[]]
    $MacAddress 
  )
 
  begin
  {
    # instantiate a UDP client:
    $UDPclient = [System.Net.Sockets.UdpClient]::new()
  }
  process
  {
    foreach($_ in $MacAddress)
    {
      try {
        $currentMacAddress = $_
        
        # get byte array from mac address:
        $mac = $currentMacAddress -split '[:-]' |
          # convert the hex number into byte:
          ForEach-Object {
            [System.Convert]::ToByte($_, 16)
          }
 
        #region compose the "magic packet"
        
        # create a byte array with 102 bytes initialized to 255 each:
        $packet = [byte[]](,0xFF * 102)
        
        # leave the first 6 bytes untouched, and
        # repeat the target mac address bytes in bytes 7 through 102:
        6..101 | Foreach-Object { 
          # $_ is indexing in the byte array,
          # $_ % 6 produces repeating indices between 0 and 5
          # (modulo operator)
          $packet[$_] = $mac[($_ % 6)]
        }
        
        #endregion
        
        # connect to port 400 on broadcast address:
        $UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)
        
        # send the magic packet to the broadcast address:
        $null = $UDPclient.Send($packet, $packet.Length)
        Write-Verbose "sent magic packet to $currentMacAddress..."
      }
      catch 
      {
        Write-Warning "Unable to send ${mac}: $_"
      }
    }
  }
  end
  {
    # release the UDF client and free its memory:
    $UDPclient.Close()
    $UDPclient.Dispose()
  }
}

它可以用来唤醒计算机,如下所示:

Invoke-WakeOnLan -MacAddress '24:EE:9A:54:1B:E5'

文章 如何使用 PowerShell 发送 LAN 唤醒 (WOL) 魔术包 有这个更短的代码:

$Mac = "1A:2B:3C:4D:5E:6F"
$MacByteArray = $Mac -split "[:-]" | ForEach-Object { [Byte] "0x$_"}
[Byte[]] $MagicPacket = (,0xFF * 6) + ($MacByteArray  * 16)
$UdpClient = New-Object System.Net.Sockets.UdpClient
$UdpClient.Connect(([System.Net.IPAddress]::Broadcast),7)
$UdpClient.Send($MagicPacket,$MagicPacket.Length)
$UdpClient.Close()

还有一个 PowerShell 脚本可以在 唤醒.ps1,用作:

Wake A0DEF169BE02

相关内容