Login | |
|
 |
RE: Ping & Excute Script - 4/16/2007 11:27:35 AM
|
|
 |
|
| |
Sc4rEye
Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
|
Okay, I have been playing with this for a few hours now. I was thinking why should I have a vb script call a batch file which in turns does something that vbscirpt can probably do. So I went back to the drawing board. Took whatever information I had and build on that. One thing I did learn is that you can do the same thing many different ways. Basically, I need to connect to my router which is running unix/linux but we are connecting to it via SSH, there is a free program out there called PuTTY which can be used to login and exexcute commands at a terminal window. By the way this software is free, you can google and download it. So what I had to do was, instead of this script calling a batch file to execute a telenet session (not secure) I wanted it to create a telnet/ssh session within the script. After trial-n-error I finally got it. Basically, if the IP fails, it will create a PuTTY session, login with username and password, and execute whatever commands I put in. Dim oShell : Set oShell = WScript.CreateObject ("WSCript.shell") IF INSTR(1, Wscript.FullName, "CScript", VBTEXTCOMPARE) = 0 THEN oShell.Run "cscript """ & Wscript.ScriptFullName & """", 0, FALSE Wscript.Quit END IF Dim arrIPAddr : arrIPAddr = Array("192.168.222.1") Dim strIP For Each strIP In arrIPAddr If Not Reachable(strIP) Then If Reachable("www.google.com") Then oShell.Run ("c:\putty\putty -l yourusername 192.168.1.1 -pw yourpassword") Wscript.Sleep 2000 oShell.SendKeys "ipsec eroute {Enter}" Wscript.Sleep 10000 oShell.SendKeys "clear {Enter}" Wscript.Sleep 2000 oShell.SendKeys "exit {Enter}" End If End If Next Function Reachable(strComputer) ' On Error Resume Next Dim objShell, objExec, strCmd, strTemp strCmd = "ping -n 1 " & strComputer Set objShell = CreateObject("WScript.Shell") Set objExec = objShell.Exec(strCmd) strTemp = UCase(objExec.StdOut.ReadAll) If InStr(strTemp, "REPLY FROM") Then Reachable = True Else Reachable = False End If End Function As you can see above I am only using one IP to keep in simple since I am still a n00b. What I need to do now. Is this, I have been looking around for info but I really can't find it or understand it. So hopefully someone here might be able to help. This is what I have to do and I think I am done with this project. Dim arrIPAddr : arrIPAddr = Array("192.168.1.1", "192.168.2.1", "192.168.3.1", _ "192.168.4.1", "192.168.5.1", "192.168.6.1") Take the failed IP which everone that may be and associate it with (192.168.1.1) <------- Run this if 192.168.1.1 fails Wscript.Sleep 2000 oShell.SendKeys "ipsec eroute 1{Enter}" Wscript.Sleep 10000 oShell.SendKeys "clear {Enter}" Wscript.Sleep 2000 oShell.SendKeys "exit {ENTER}" (192.168.2.1) <------- Run this if 192.168.2.1 fails Wscript.Sleep 2000 oShell.SendKeys "ipsec eroute 2{Enter}" Wscript.Sleep 10000 oShell.SendKeys "clear {Enter}" Wscript.Sleep 2000 oShell.SendKeys "exit {ENTER}" so on and so fourth. I have looked around but I really can't find anything. Or maybe I did, but don't understand it yet. Again, Any help, suggestions, comments are appreciated. Thanks ScarEye
< Message edited by Sc4rEye -- 4/16/2007 11:32:01 AM >
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/16/2007 4:33:33 PM
|
|
 |
|
| |
dm_4ever
Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
If the batch files are similar with small differences...I'd probably have the vbs write the appropriate commands to the batch and then call it. The reason is that if putty accept commands from the cmd line, then it is more reliable and safer to use than SendKeys...unless it exposes a COM object you can use...which I doubt since it is a free program.
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/17/2007 12:06:20 AM
|
|
 |
|
| |
Country73
Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
|
Maybe just a simple SPLIT or MID would work against those IP Addresses. That way you know which batch file to call, or you can have one batch file accept input from your script. If the main thing you are going off of is the third octet of the Address, which is what I'm gathering from your posts, then just extract that information from the IP Address. 192.168.1.1 -> myfile1.bat 192.168.2.1 -> myfile2.bat
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/17/2007 3:20:05 AM
|
|
 |
|
| |
Country73
Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
|
Make sure you look over the script documents, you can find them in this post http://www.visualbasicscript.com/fb.aspx?m=24727, to get a better understanding. Just a quick stab at it here; using SPLIT. Dim strIP For Each strIP In arrIPAddr mySplit = SPLIT(strIP,".") myVal = mySplit(2) 'on and address of 192.168.X.X - 0 = 192; 1 = 168; etc... If Not Reachable(strIP) Then If Reachable("www.google.com") Then oShell.Run "C:\myfile" & myVal & ".bat" 'would now equal "c:\myfile1.bat" or "c:\myfile2.bat" etc... End If End If Next
< Message edited by Country73 -- 4/17/2007 3:23:39 AM >
|
|
| |
|
|
|
|
|