ajtsystems
IS-IT--Management
Hi,
Written this code to call telnet then run a do while loop if the IP address of the server entered is not pingable. I am going to use it to reboot remotely some gprs signs on our network
anyway something strange happens when I run it and supply the text box with an IP address. It seems the sub runs twice and creates to cmd logins for telnet,
Have I done something wrong with the Do while Loop?
IPAddress = inputbox( "Please Enter IP Address:" )
Username = inputbox( "username:" )
password = inputbox( "password:" )
'==========================================================================
' The following function will test if a machine is reachable via a ping
' using WMI and the Win32_PingStatus
'==========================================================================
If Reachable(IPAddress) Then
'WScript.Echo "Computer is Reachable"
Else
WScript.Echo "Computer is Unreachable!"
End If
Function Reachable(strComputer)
' On Error Resume Next
Dim wmiQuery, objWMIService, objPing, objStatus
wmiQuery = "Select * From Win32_PingStatus Where " & _
"Address = '" & strComputer & "'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
Reachable = False 'if computer is unreacable, return false
Else
Reachable = True 'if computer is reachable, return true
End If
Next
if reachable = true then
call TelnetFunc
else
wscript.echo "Contact TSS"
wscript.quit
end if
End Function
Sub Telnetfunc
Set WshShell = WScript.CreateObject("WScript.Shell")
wshshell.run("telnet " & IPAddress & " 21")
end sub
do while reachable(IPAddress) = false
wscript.sleep 10000
If Reachable(IPAddress) Then
'WScript.Echo "Computer is Reachable"
Else
WScript.Echo "Computer is Unreachable!"
End If
loop
wscript.sleep 10000
wscript.echo "Ping back"
James
Written this code to call telnet then run a do while loop if the IP address of the server entered is not pingable. I am going to use it to reboot remotely some gprs signs on our network
anyway something strange happens when I run it and supply the text box with an IP address. It seems the sub runs twice and creates to cmd logins for telnet,
Have I done something wrong with the Do while Loop?
IPAddress = inputbox( "Please Enter IP Address:" )
Username = inputbox( "username:" )
password = inputbox( "password:" )
'==========================================================================
' The following function will test if a machine is reachable via a ping
' using WMI and the Win32_PingStatus
'==========================================================================
If Reachable(IPAddress) Then
'WScript.Echo "Computer is Reachable"
Else
WScript.Echo "Computer is Unreachable!"
End If
Function Reachable(strComputer)
' On Error Resume Next
Dim wmiQuery, objWMIService, objPing, objStatus
wmiQuery = "Select * From Win32_PingStatus Where " & _
"Address = '" & strComputer & "'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
Reachable = False 'if computer is unreacable, return false
Else
Reachable = True 'if computer is reachable, return true
End If
Next
if reachable = true then
call TelnetFunc
else
wscript.echo "Contact TSS"
wscript.quit
end if
End Function
Sub Telnetfunc
Set WshShell = WScript.CreateObject("WScript.Shell")
wshshell.run("telnet " & IPAddress & " 21")
end sub
do while reachable(IPAddress) = false
wscript.sleep 10000
If Reachable(IPAddress) Then
'WScript.Echo "Computer is Reachable"
Else
WScript.Echo "Computer is Unreachable!"
End If
loop
wscript.sleep 10000
wscript.echo "Ping back"
James