WOL per cmd&powershell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@ECHO off
@setlocal EnableDelayedExpansion
@goto label1
@echo this lines should not be printed
@echo and this whole block (lines 4-8) can actually be removed
@echo I added these just for Charlie22911
@:label1
@set LF=^
@SET command=#
@FOR /F "tokens=*" %%i in ('findstr -bv @ "%~f0"') DO SET command=!command!!LF!%%i
@powershell -noprofile -noexit -command !command! & goto:eof
# *** POWERSHELL CODE STARTS HERE *** #
$Mac = 'D43D7E6E3206'
# to ensure that the packet is sent out at the correct
# interface, use the broadcast address of the network
# here we've a 25er
$broadcastIP = '192.168.1.127'
$IPAddress = '192.168.1.31'
$Port = '445'
# send wol-packet
$UdpClient = New-Object Net.Sockets.UdpClient
$remoteip = [System.Net.IPAddress]::Parse($broadcastIP)
$IPEndPoint = New-Object Net.IPEndPoint $remoteip, 9
$MAC = [Net.NetworkInformation.PhysicalAddress]::Parse($Mac.ToUpper())
$Packet = [Byte[]](,0xFF*6)+($MAC.GetAddressBytes()*16)
# Broadcast UDP packets to the Broadcast
$UdpClient.EnableBroadcast = $true
$UdpClient.DontFragment = $true
$UdpClient.Ttl = 64
$UdpClient.Send($Packet, $Packet.Length, $IPEndPoint) | Out-Null
$UdpClient.Close()
$UdpClient.Dispose()
# wait till server responds
do {
Write-Host "waiting for $IPAddress ..."
sleep 3
} until(Test-NetConnection $IPAddress -Port $Port | ? { $_.TcpTestSucceeded } )
Write-Host "$IPAddress is alive ..."
sleep 3
exit
Dieser Eintrag ist vom Autor unter
CC BY 4.0
lizensiert.