Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: Ping & Excute Script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,45873
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Ping & Excute Script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Ping & Excute Script - 4/16/2007 6:44:21 AM   
  Sc4rEye

 

Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
I can create one script for each batch file.  But I would like to have 1 script.  If possible.


Thanks again,
ScarEye

(in reply to Sc4rEye)
 
 
Post #: 21
 
 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 >

(in reply to Sc4rEye)
 
 
Post #: 22
 
 RE: Ping & Excute Script - 4/16/2007 4:03:30 PM   
  dm_4ever


Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Is the only thing different in your batch files the IP address?

_____________________________

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

(in reply to Sc4rEye)
 
 
Post #: 23
 
 RE: Ping & Excute Script - 4/16/2007 4:16:52 PM   
  Sc4rEye

 

Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
dm_4ever,

   Each batch file connects to the router and executes a command depending on which IP is not working. 


Store1 = 192.168.1.1
Store 2 = 192.168.2.1



So if the IP address of Store 1 is down.   This is what the batch file does.


ipsec auto --down store 1   (This takes the tunnel down out of the system)
ipsec auto --add store 1     (This command get is ready to use)
ipsec auto --up store 1       (This command starts initating the tunnel)

So now if store 2 was down (192.168.2.1)  the batch file would do everything the same
except change from store 1 to store 2

ipsec auto --down store 2
ipsec auto --add store 2    
ipsec auto --up store 2


Thanks again.
ScarEye 


(in reply to dm_4ever)
 
 
Post #: 24
 
 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

(in reply to Sc4rEye)
 
 
Post #: 25
 
 RE: Ping & Excute Script - 4/16/2007 5:04:38 PM   
  Sc4rEye

 

Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
Okay, But I am still stuck,  Then what I would need to do is this.

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")  


if 192.168.1.1 fails then ping www.google.com if pass then

execute c:\myfile1.bat

move on

if 192.168.2.1 fails then ping www.google.com if pass then

execute c:\myfile2.bat

if 192.168.3.1 fails then ping www.google.com if fails then nothing go to the next IP.


so on and so fourth


I have been searching, but I can't find anything.


Thanks
ScarEye

(in reply to dm_4ever)
 
 
Post #: 26
 
 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

(in reply to Sc4rEye)
 
 
Post #: 27
 
 RE: Ping & Excute Script - 4/17/2007 2:21:03 AM   
  Sc4rEye

 

Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
Thanks for your reply Country73,  Can you please give me some examples on how I could acomplish this. 
If possible ?



Thank
ScarEye

(in reply to Country73)
 
 
Post #: 28
 
 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 >

(in reply to Sc4rEye)
 
 
Post #: 29
 
 
Page:  <<   < prev  1 [2]
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: Ping & Excute Script Page: <<   < prev  1 [2]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts