#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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(mole)
and 1300 anonymous users online.
|
|
|