NASLite Network Attached Storage

www.serverelements.com
Task-specific simplicity with low hardware requirements.
It is currently Fri Mar 29, 2024 9:42 am

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Nov 17, 2011 11:14 am 
Offline

Joined: Fri Sep 23, 2011 10:56 am
Posts: 5
First attempt at proper scripting so it might be a bit messy. Help tidying it and ideas welcome.

Wanted a script to shut down naslite server after watching movies in either the bedroom, pc room, lounge or laptop - all machines have fixed ip.
Wanted to check that the machine i was using was the only one running and therefore no other machines using nas box.
Option to ignore other machines detected on network, or cancel shutdown of nas box.
Option to ignore ip of machine that script is on to avoid false reporting of active client.

I came up with this, the message boxes arent particularly great, may be better if all the results were displayed in one box but tbh i dont know how to do it!
It works and so im reasonably happy with it.

Feel free to modify to suit your own use, or suggest ways i could improve it.
Cheers!

If you want to copy and paste it start below, save as .vbs


'Naslite box shutdown
'By Rick

'shutdown NAS box only if no client machines on network
'if client detected option to cancel shutdown or ignore
'identify active machines with ping

'define IP *.*.*.
'define start ip
'define end ip
'define ignore ip (pc script is run on)
'ignore will not work on first ip in range so just set start ip to one above on that machine

strSubnet = "192.168.1."
intStartIP = 2
intEndIP = 5
ignoreIP = 3

strResult = "No response"

x = intStartIP
Do Until x > intEndIP
strIP = CStr(x)
strComputer = strSubnet & strIP

CreateObject("WScript.Shell").Popup (strComputer & " Pinging..."), 2, "NAS Box Client Check.", 64+4096

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & strComputer & "'")

For Each objItem in colItems
If objItem.StatusCode = 0 Then
Set WshShell = CreateObject("Wscript.Shell")
RetValue = WshShell.Popup (strComputer & " Active - Ignore?", -1, "Nas Box Client Check.", 1+4096+32)
Select Case RetValue
Case 1: objItem.StatusCode = 1
Case 2: Call Abort
Case -1: Call Abort
End Select

strResult = "Reply received"
End If
Next
x = x + 1
If x=ignoreIP then x=x+1
If x>intEndIP then Call Shutdownscript
Loop

'NAS box shutdown code
'enter poweroff as username to shutdown
'enter reboot as username to reboot
'change password to correct one
'change telnet target ip to nas box

Sub Shutdownscript
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run"telnet.exe 192.168.1.6"
WScript.Sleep 500
WshShell.SendKeys"shutdown"
WshShell.SendKeys("{Enter}")
WScript.Sleep 500
WshShell.SendKeys"password"
WshShell.SendKeys("{Enter}")
End Sub

Sub Abort
CreateObject("WScript.Shell").Popup ("Nas Shutdown Aborted."), -1, "NAS Box Client Check.", 0+48+4096
Select Case RetValue
Case 1: Wscript.Quit
Case -1: Wscript.Quit
End Select
If objItem.StatusCode = 0 Then Wscript.Quit
End Sub


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group