#76015 - 2003-07-22 02:02 PM
WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
this is my WOL routine (from a previous thread)
WOL.exe is located in %windir% WOL requires the MAC address of the target PC
The only way of getting the MAC, is either have each PC log it to a central location or collect it from the DHCP server.
I use MS DHCP server and dhcpcmd.exe to retrieve the MAC address and populate an array (compname,macaddr)
code:
$server = '192.168.1.2'
$command = 'cmd /c %windir%\dhcpcmd.exe '+ $server +' getsuperscopetable | find "Subnet address"' $superscope = WSHPipe($command,1)
for each $scope in $superscope $subnet = trim(split($scope,'=')[1]) $command = 'cmd /c %windir%\dhcpcmd.exe '+ $server +' enumclients ' + $subnet+' -h' $output = WSHPipe($command,1) $x = 0 For each $line in $output if val(left($line,1)) $arr_IPaddr[$x] = trim(substr($line,4,15)) $arr_Computer[$x] = split(trim(substr($line,21,16)),'.')[0] $arr_MACaddr[$x] = trim(substr($line,38,17)) $x = $x +1 redim preserve $arr_IPaddr[$x] redim preserve $arr_Computer[$x] redim preserve $arr_MACaddr[$x] endif next next for each $item in $ListViewEx1.items if left($item.SubItems(3).Text,6) = 'Offlin' and $item.subitems(1).text = '¤' $Computer = $item.SubItems(2).Text $pos = ascan($arr_Computer,$computer) if $pos +1 $mac = $arr_MACaddr[$pos] Status("Sending WOL to $computer") shell 'cmd /c %windir%\wol.exe ' + $mac +' > nul' else Status("MAC Addr Not available for $computer") endif endif next sleep 15 endfunction
This is just the code from a current project (Remote Execution Manager), but if you try, you can figure out the details
|
|
Top
|
|
|
|
#76016 - 2003-07-22 02:35 PM
Re: WOL
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
There are other ways to get the MAC Address..
For example, ePO logs this too.
Kent [ 22. July 2003, 14:36: Message edited by: kdyer ]
|
|
Top
|
|
|
|
#76017 - 2003-07-22 02:38 PM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
well... SMS has it also, but good luck in getting to it
|
|
Top
|
|
|
|
#76018 - 2003-07-22 03:11 PM
Re: WOL
|
Anonymous
Anonymous
Unregistered
|
@ADDRESS works too!
|
|
Top
|
|
|
|
#76019 - 2003-07-22 03:35 PM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
now Mike, tell me how you @address a computer that is turned off.
That is what I thought.
|
|
Top
|
|
|
|
#76020 - 2003-07-22 03:40 PM
Re: WOL
|
Anonymous
Anonymous
Unregistered
|
Chill out!! This post says nothing about the computer being on or off or how or when you wanted to get a list of the MAC addreses.
|
|
Top
|
|
|
|
#76021 - 2003-07-22 03:43 PM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Well... It is easy to WOL a computer that is already on... and it always works.
|
|
Top
|
|
|
|
#76024 - 2003-07-22 03:50 PM
Re: WOL
|
Anonymous
Anonymous
Unregistered
|
Thanks sealeopard! That's what I was getting to, only in a lot less words! You could use the @ADDRESS to create your list when the machine logon.
|
|
Top
|
|
|
|
#76026 - 2003-07-22 03:54 PM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
and that is what I said
quote: The only way of getting the MAC, is either have each PC log it to a central location or collect it from the DHCP server.
however, I didn't state that I'd use @address to do it
in any case, lets drop this line of discussion before someone goes Gavin. [ 22. July 2003, 15:56: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#76027 - 2003-07-22 07:22 PM
Re: WOL
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
Here is a code snippet to pull what you need from an sms site. I yanked it out of one of my kixforms programs and modified a little for you. It should get you started.
Personally I would be happy if all I had to do was just find the off computer's information. Our network group has blocked udp traffic from crossing subnets. That means I have to find a computer that is on and usable in the subnet of a off computer.
$WMISMSServer = fnWMIConnect($txtSMSSiteServer,,,,,"/root/sms/site_" + $txtSMSSiteCode) IF VarType($WMISMSServer) <> 9 $WMISMSServerStatus = "NoAccess" ELSE $WMISMSServerStatus = "Access" $ComputerResourceID = fnSMSGetResourceID($Computer, $WMISMSServer) $oClient = $WMISMSServer.ExecQuery ("Select IPAddresses, IPSubnets, MacAddresses FROM SMS_R_System WHERE ResourceID=" + $ComputerResourceID) FOR EACH $Client IN $oClient $Index = 0 FOR EACH $IP IN $Client.IPAddresses IF $IP = $IPAddress $MACAddress = Join(Split($Client.MacAddresses($Index), ":", -1), "") $OffSubnet = $Client.IPSubnets($Index) $oSubnetMask = $WMISMSServer.ExecQuery ("Select * FROM SMS_G_System_NETWORK_ADAPTER_CONFIGURATION WHERE ResourceID=" + $ComputerResourceID) FOR EACH $SubnetMask IN $oSubnetMask IF $SubnetMask.IPAddress = $IPAddress $OffMask = $SubnetMask.IPSubnet ENDIF NEXT ENDIF $Index = $Index + 1 ') NEXT ') NEXT ENDIF
_________________________
Kelly
|
|
Top
|
|
|
|
#76028 - 2003-07-23 04:02 AM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
what are the functions used here?
fnWMIConnect()?? etc
|
|
Top
|
|
|
|
#76029 - 2003-07-23 06:55 PM
Re: WOL
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
Sorry. It been busy at work. fnWMIConnect is from the UDF library. I don't think I hacked it much. If I missed something please yell.
fnWMIConnect
FUNCTION fnWMIConnect(OPTIONAL $sComputer, OPTIONAL $sUSER, OPTIONAL $spwd, OPTIONAL $ImpLevel, OPTIONAL $authLevel, OPTIONAL $sNamespace) ;-- This will make a WMI connection to a namespace on a computer. ;ImpersonationLevels: ;--- Anonymous: Hides the credentials of the caller. Calls to WMI may fail with this impersonation level. ;--- IdentIFy: Allows objects to query the credentials of the caller. Calls to WMI may fail with this impersonation level. ;--- Impersonate: Default. Allows objects to USE the credentials of the caller. This is the recommended impersonation level ;--- for WMI Scripting API calls. ;--- Delegate: Allows objects to permit other objects to USE the credentials of the caller. This impersonation, which&nb sp;will ;--- work with WMI Scripting API calls but may constitute an unnecessary security risk, is supported only  ;under Windows 2000. DIM $locator, $context, $namespace, $moniker SELECT CASE $ImpLevel=1 $ImpLevel = "Anonymous" CASE $ImpLevel=2 $ImpLevel = "IdentIFy" CASE $ImpLevel=3 $ImpLevel = "impersonate" CASE $ImpLevel=4 $ImpLevel = "Delegate" CASE 1 $ImpLevel = "impersonate" ENDSELECT $authLevel = "pktPrivacy" $moniker = "winmgmts:{impersonationLevel=" + $ImpLevel + ",authenticationLevel=" + $authLevel+"}!\\" $namespace = "\root\cimv2" IF $sNamespace $namespace = $sNamespace ENDIF IF NOT $sComputer OR $sComputer = "@Wksta" OR $sComputer = "." ; local host $sComputer = "@Wksta" $fnWMIConnect = GetObject($moniker+$sComputer+$namespace) ELSE ; remote host IF ($sUSER AND $spwd) OR $sUSER IF Substr($namespace, 1, 1) = "\" $namespace = Substr($namespace, 2, Len($namespace) - 1) ENDIF $locator = CreateObject("WbemScripting.SWbemLocator") $context = CreateObject("WbemScripting.SWbemNamedValueSet") $fnWMIConnect = $locator.ConnectServer($sComputer,$namespace,$sUSER,$spwd,"","",0,$context) ELSE ; current (local) credentials $fnWMIConnect = GetObject($moniker+$sComputer+$namespace) ENDIF ENDIF IF @Error $fnWMIConnect = @SError ENDIF EXIT @Error ENDFUNCTION
fnSMSGetResourceID
FUNCTION fnSMSGetResourceID($ComputerName, $WMISMSServerName) ;--- This function will return the Resource ID for a computer from the SMS Server. DIM $SMSGetResourceIDError, $SMSGetResourceIDQuery $SMSGetResourceIDQuery = 'Select ResourceID from SMS_R_System where Name=' + '"' + $ComputerName + '"' $SMSGetResourceIDObjEnumerator = $WMISMSServerName.ExecQuery($SMSGetResourceIDQuery) $SMSGetResourceIDError = @Error IF $SMSGetResourceIDError <> 0 $fnSMSGetResourceID = 0 ELSE FOR EACH $SMSGetResourceIDObjInstance IN $SMSGetResourceIDObjEnumerator FOR EACH $SMSGetResourceIDOProp IN $SMSGetResourceIDObjInstance.Properties_ $fnSMSGetResourceID = $SMSGetResourceIDOProp.Value NEXT NEXT ENDIF $SMSGetResourceIDObjEnumerator = '' EXIT $SMSGetResourceIDError ENDFUNCTION
_________________________
Kelly
|
|
Top
|
|
|
|
#76030 - 2003-07-24 03:51 PM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I'm not getting any results from: FUNCTION fnSMSGetResourceID($ComputerName, $WMISMSServerName)
there is no error here $WMISMSServerName.ExecQuery...
but it doesn't return any data
|
|
Top
|
|
|
|
#76031 - 2003-07-24 04:24 PM
Re: WOL
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
Okay, I finally got off my duff and gave this the attention it deserves. I forgot to include a ping function. You have to have the computer's IP to match to the computer's IP in SMS. I really need to go through this and clean it up.
This script works here.
BREAK ON DIM $Computer, $MACAddress, $OffSubnet, $OffMask
$txtSMSSiteServer = "SITESERVER" $txtSMSSiteCode = "SITECODE" $Computer = "COMPUTERNAME"
$RC = fnPingQuick($Computer, 1, 1000, 32) $WMISMSServer = fnWMIConnect($txtSMSSiteServer,,,,,"/root/sms/site_" + $txtSMSSiteCode) IF VarType($WMISMSServer) <> 9 $WMISMSServerStatus = "NoAccess" ELSE $WMISMSServerStatus = "Access" $ComputerResourceID = fnSMSGetResourceID($Computer, $WMISMSServer) $oClient = $WMISMSServer.ExecQuery ("Select IPAddresses, IPSubnets, MacAddresses FROM SMS_R_System WHERE ResourceID=" + $ComputerResourceID) FOR EACH $Client IN $oClient $Index = 0 FOR EACH $IP IN $Client.IPAddresses IF $IP = $IPAddress $MACAddress = Join(Split($Client.MacAddresses($Index), ":", -1), "") $OffSubnet = $Client.IPSubnets($Index) $oSubnetMask = $WMISMSServer.ExecQuery ("Select * FROM SMS_G_System_NETWORK_ADAPTER_CONFIGURATION WHERE ResourceID=" + $ComputerResourceID) FOR EACH $SubnetMask IN $oSubnetMask IF $SubnetMask.IPAddress = $IPAddress $OffMask = $SubnetMask.IPSubnet ENDIF NEXT ENDIF $Index = $Index + 1 NEXT NEXT ENDIF
? $WMISMSServerStatus ? $Computer ? $ComputerResourceID ? $MACAddress ? $OffSubnet ? $OffMask
;================================================================ FUNCTION fnWMIConnect(OPTIONAL $sComputer, OPTIONAL $sUSER, OPTIONAL $spwd, OPTIONAL $ImpLevel, OPTIONAL $authLevel, OPTIONAL $sNamespace) ;-- This will make a WMI connection to a namespace on a computer. ;ImpersonationLevels: ;--- Anonymous: Hides the credentials of the caller. Calls to WMI may fail with this impersonation level. ;--- IdentIFy: Allows objects to query the credentials of the caller. Calls to WMI may fail with this impersonation level. ;--- Impersonate: Default. Allows objects to USE the credentials of the caller. This is the recommended impersonation level ;--- for WMI Scripting API calls. ;--- Delegate: Allows objects to permit other objects to USE the credentials of the caller. This impersonation, which&am p;nb sp;will ;--- work with WMI Scripting API calls but may constitute an unnecessary security risk, is supported only  ; ;under Windows 2000. DIM $locator, $context, $namespace, $moniker SELECT CASE $ImpLevel=1 $ImpLevel = "Anonymous" CASE $ImpLevel=2 $ImpLevel = "IdentIFy" CASE $ImpLevel=3 $ImpLevel = "impersonate" CASE $ImpLevel=4 $ImpLevel = "Delegate" CASE 1 $ImpLevel = "impersonate" ENDSELECT $authLevel = "pktPrivacy" $moniker = "winmgmts:{impersonationLevel=" + $ImpLevel + ",authenticationLevel=" + $authLevel+"}!\\" $namespace = "\root\cimv2" IF $sNamespace $namespace = $sNamespace ENDIF IF NOT $sComputer OR $sComputer = "@Wksta" OR $sComputer = "." ; local host $sComputer = "@Wksta" $fnWMIConnect = GetObject($moniker+$sComputer+$namespace) ELSE ; remote host IF ($sUSER AND $spwd) OR $sUSER IF Substr($namespace, 1, 1) = "\" $namespace = Substr($namespace, 2, Len($namespace) - 1) ENDIF $locator = CreateObject("WbemScripting.SWbemLocator") $context = CreateObject("WbemScripting.SWbemNamedValueSet") $fnWMIConnect = $locator.ConnectServer($sComputer,$namespace,$sUSER,$spwd,"","",0,$context) ELSE ; current (local) credentials $fnWMIConnect = GetObject($moniker+$sComputer+$namespace) ENDIF ENDIF IF @Error $fnWMIConnect = @SError ENDIF EXIT @Error ENDFUNCTION ;================================================================ FUNCTION fnSMSGetResourceID($ComputerName, $WMISMSServerName) ;--- This function will return the Resource ID for a computer from the SMS Server. DIM $SMSGetResourceIDError, $SMSGetResourceIDQuery $SMSGetResourceIDQuery = 'Select ResourceID from SMS_R_System where Name=' + '"' + $ComputerName + '"' $SMSGetResourceIDObjEnumerator = $WMISMSServerName.ExecQuery($SMSGetResourceIDQuery) $SMSGetResourceIDError = @Error IF $SMSGetResourceIDError <> 0 $fnSMSGetResourceID = 0 ELSE FOR EACH $SMSGetResourceIDObjInstance IN $SMSGetResourceIDObjEnumerator FOR EACH $SMSGetResourceIDOProp IN $SMSGetResourceIDObjInstance.Properties_ $fnSMSGetResourceID = $SMSGetResourceIDOProp.Value NEXT NEXT ENDIF $SMSGetResourceIDObjEnumerator = '' EXIT $SMSGetResourceIDError ENDFUNCTION ;================================================================ FUNCTION fnPingQuick($Address, OPTIONAL $PingCount, OPTIONAL $PingWait, OPTIONAL $PacketSize, OPTIONAL $PingTTL) ;---------------------------------------------------------------- ;--- This function will Ping an address and return an error code ;--- , an IP address and an IP host name. ;--- 0 - The address is on. ;--- 1 - The address is a slow link, such as RAS/ISDN/VPN. ;--- 2 - The address is off. ;--- 3 - The address does not exist. ;---------------------------------------------------------------- GLOBAL $IPAddress, $IPName, $IPError, $IPAvgTime, $IPLinkSpeed DIM $WshShell, $oExec, $IPTime, $IPErrorCode, $PingLine, $Index1, $Index2, $Index3, $Index4 $IPAddress = '' $IPName = '' $IPError = 'Unknown error' $IPErrorCode = 3 IF $PingCount = '' $PingCount = 4 ENDIF IF $PingWait = '' $PingWait = 4000 ENDIF IF $PacketSize = '' $PacketSize = 32 ENDIF IF $PingTTL = '' $PingTTL = 128 ENDIF $IPTime = '' $WshShell = CreateObject ('WScript.Shell') $oExec = $WshShell.Exec ('%Comspec% /e:1024 /C ping -a -n ' + $PingCount + ' -w ' + $PingWait + ' -l ' + $PacketSize + ' -i ' + $PingTTL + ' ' + $Address) WHILE NOT $oExec.StdOut.AtEndOfStream $PingLine = $oExec.StdOut.ReadLine SELECT CASE InStr ($PingLine, 'Pinging ') $IPError = 'Pinging' $Index1 = 9 IF InStr ($PingLine, '[') IF InStr ($Address, '.') $Index2 = InStr ($PingLine, '.') ELSE $Index2 = InStr ($PingLine, '[') - 1 ENDIF $Index3 = InStr ($PingLine, '[') + 1 $Index4 = InStr ($PingLine, ']') $IPName = Substr ($PingLine, $Index1, $Index2 - $Index1) $IPAddress = Substr ($PingLine, $Index3, $Index4 - $Index3) ELSE $IPAddress = '' $IPName = '' ENDIF CASE InStr ($PingLine, 'TTL expired in transit') $IPError = 'TTL expired in transit' $IPErrorCode = 2 CASE InStr ($PingLine, 'TTL expired during reassembly') $IPError = 'TTL expired during reassembly' $IPErrorCode = 2 CASE InStr ($PingLine, 'Request timed out') $IPError = 'Request timed out' $IPErrorCode = 2 CASE InStr ($PingLine, 'host unreachable') $IPError = 'host unreachable' $IPErrorCode = 2 CASE InStr ($PingLine, 'net unreachable') $IPError = 'net unreachable' $IPErrorCode = 3 CASE InStr ($PingLine, 'protocol unreachable') $IPError = 'protocol unreachable' $IPErrorCode = 3 CASE InStr ($PingLine, 'port unreachable') $IPError = 'port unreachable' $IPErrorCode = 3 CASE InStr ($PingLine, 'Bad') $IPError = 'Bad' $IPErrorCode = 3 CASE InStr ($PingLine, 'Unknown host') $IPError = 'Unknown host' $IPErrorCode = 3 CASE InStr ($PingLine, 'Reply from') $IPError = 'Reply from' $IPErrorCode = 0 ENDSELECT $PingLine = ReadLine(10) LOOP $PingLineQuick = $IPError EXIT $IPErrorCode ENDFUNCTION
_________________________
Kelly
|
|
Top
|
|
|
|
#76032 - 2003-07-24 05:18 PM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
|
Top
|
|
|
|
#76033 - 2003-07-24 05:38 PM
Re: WOL
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
my god SMS sucks
it takes almost 30 seconds to do a list 5 computers... and that is after I pulled out the ping routine...
code:
BREAK ON DIM $Computer, $MACAddress
$WMISMSServer = fnWMIConnect("SMSserver",,,,,"/root/sms/site_000") IF VarType($WMISMSServer) = 9
for each $Computer in split('wheelerc wheelerc-400 wheelerc-510 wheelerc-LAP') $ResourceID = fnSMSGetResourceID($Computer, $WMISMSServer) $MACAddress = fnGetMAC($ResourceID) ? $Computer +' '+ $MACAddress next ELSE ? "NoAccess" ENDIF
;================================================================ FUNCTION fnWMIConnect(OPTIONAL $sComputer, OPTIONAL $sUSER, OPTIONAL $spwd, OPTIONAL $ImpLevel, OPTIONAL $authLevel, OPTIONAL $sNamespace) DIM $locator, $context, $namespace, $moniker $moniker = "winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" $namespace = iif($sNamespace,$sNamespace,"\root\cimv2") IF NOT $sComputer OR $sComputer = "@Wksta" OR $sComputer = "." $sComputer = "@Wksta" $fnWMIConnect = GetObject($moniker+$sComputer+$namespace) ELSE IF ($sUSER AND $spwd) OR $sUSER IF Substr($namespace, 1, 1) = "\" $namespace = Substr($namespace, 2, Len($namespace) - 1) ENDIF $locator = CreateObject("WbemScripting.SWbemLocator") $context = CreateObject("WbemScripting.SWbemNamedValueSet") $fnWMIConnect = $locator.ConnectServer($sComputer,$namespace,$sUSER,$spwd,"","",0,$context) ELSE $fnWMIConnect = GetObject($moniker+$sComputer+$namespace) ENDIF ENDIF IF @Error $fnWMIConnect = @SError ENDIF EXIT @Error ENDFUNCTION ;================================================================ FUNCTION fnSMSGetResourceID($ComputerName, $WMISMSServerName) ;--- This function will return the Resource ID for a computer from the SMS Server. DIM $SMSGetResourceIDError, $SMSGetResourceIDQuery $SMSGetResourceIDQuery = 'Select ResourceID from SMS_R_System where Name=' + '"' + $ComputerName + '"' $SMSGetResourceIDObjEnumerator = $WMISMSServerName.ExecQuery($SMSGetResourceIDQuery) $SMSGetResourceIDError = @Error IF $SMSGetResourceIDError <> 0 $fnSMSGetResourceID = 0 ELSE FOR EACH $SMSGetResourceIDObjInstance IN $SMSGetResourceIDObjEnumerator FOR EACH $SMSGetResourceIDOProp IN $SMSGetResourceIDObjInstance.Properties_ $fnSMSGetResourceID = $SMSGetResourceIDOProp.Value NEXT NEXT ENDIF $SMSGetResourceIDObjEnumerator = '' EXIT $SMSGetResourceIDError ENDFUNCTION ;================================================================ FUNCTION fnGetMAC($ComputerResourceID) $oClient = $WMISMSServer.ExecQuery ("Select MacAddresses FROM SMS_R_System WHERE ResourceID=" + $ComputerResourceID) FOR EACH $Client IN $oClient $Index = 0 FOR EACH $MAC IN $Client.MacAddresses $fnGetMAC = Join(Split($Client.MacAddresses($Index), ":", -1), "") $Index = $Index + 1 NEXT NEXT ENDFUNCTION
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 384 anonymous users online.
|
|
|