Skip to content
 

PowerShell Wake on Lan v0.1

Wake on lan e o functie disponibila pe orice placa de baza mai noua de 1900 toamna ce te lasa sa pornesti de la distanta un calculator. Principiul de functionare e cam asa: trimiti pe retea un pachet “special” ce contine MAC-ul statiei ce ce vrei sa o pornesti. Daca e configurata corect si e sub tensiune statia porneste si putem sa o administram de la distanta.
Fabricarea magic packetului e luata de la powershellguy

Pentru a rula scriptul e nevoie de un fisier csv ce contine doua informatii : nume statie si mac
exemplu

computername,mac
workstation01,001e37FF3e1b
workstation02,001e37FF3e8c

Scriptul cere de la user numele statiei si o porneste. Enjoy!

$computer=read-host "Enter Workstation to wake..."

$select=Import-Csv workstations.csv |where-object {$_.computername -eq $computer} |Select-Object mac
if ($select.mac -eq $null)
{
	echo "workstation not found.fail"
}
else
{

$select.mac  -match "(..)(..)(..)(..)(..)(..)" | out-null
$mac= [byte[]]($matches[1..6] |% {[int]"0x$_"})  

$UDPclient = new-Object System.Net.Sockets.UdpClient
$UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)
$packet = [byte[]](,0xFF * 102)
6..101 |% { $packet[$_] = $mac[($_%6)]}
$UDPclient.Send($packet, $packet.Length)
echo "workstation $computer is booting up..."
ping -n 25 $computer
}

3 Comments

  1. Stefan ROMANIA Windows Vista Mozilla Firefox 3.0.3 says:

    O mica precizare :P :
    echo “workstation not found.fail” -> echo “workstation not found. epic fail”

  2. Cosu ROMANIA WordPress 2.6.2 says:

    [...] de ieri l-am extins si i-am adaugat functii de remote shutdown si restart. Ca bonus am adaugat si epic fail [...]

Leave a Reply