Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Visual Basic Script Help

Options
  • 01-11-2019 5:17am
    #1
    Registered Users Posts: 14,026 ✭✭✭✭


    Hi all. Bity of a n00b question regarding vbs. Started a new job recently, night shifts and it's new to the company so we're basically doing sfa at the moment. It's not a very technical job, but it's middleman networking, ie: engineers get onto us, we get onto the customer and relay between the 2. Some tech knowledge is required, but not necessary.

    While I do have a good bit of experience in computing, it's mainly basic building and operation. My boss gave me a job, but it's not very high on the list of things to do, and is more of a help tool for others. Basically, it's a .vbs file which opens Putty (tool for logging into customer routers, if ye haven't heard of it), automatically logs us in with 2 separate log in details, and opens the IP of the router we're connecting to, and opens a txt file.

    Unfortunately, I have no prior knowledge of VB, or any scripting really, but I somehow managed to Google and fix the issue with the txt file not opening (didn't specify to open a notepad document before the command to open the file), but I'm stumped on another bit. I intend on learning more about vbs soon, but for now I need a hand as the internet, or my lack of understanding of what to search for, is letting me down.

    When I run the script, it first opens a text box to enter an IP to access, then it opens Putty, logs us in, and attempts to log us into the router. However, there's a 'Are you sure' question between the second username/password, and I don't know how to script for that. Anyone be able to help? I've pasted the script below, removing any company/personal information:
    Dim  Shell
    IPAdress   = InputBox("Enter your IP Address")
    Set Shell   = CreateObject("WScript.Shell")
    If IPAdress = "" Then 
    Wscript.Quit 
    End If 
    output = Shell.Run("C:\Users\USER\Desktop\putty.exe 192.x.x.x")
    wscript.sleep(1000)
    Shell.Sendkeys "LOGIN1" & VBCrLf
    wscript.sleep(1000)
    Shell.Sendkeys "PW1" & VBCrLf
    wscript.sleep(1000)
    Shell.Sendkeys "ssh"
    wscript.sleep(1000)
    Shell.Sendkeys " -l LOGIN2 " & IPAdress & VBCrLf
    wscript.sleep(1000)
    Shell.Sendkeys "PW2" & VBCrLf
    wscript.sleep(1000)
    output = Shell.Run("notepad.exe T:\path to file.txt")
    

    The issue occurs between LOGIN2 and PW2, we get the 'Are you sure' message, and the above script enters PW2, which it then fails. Anyone any suggestions? No worries if not, I'll just have to say I couldn't figure it out, which is understandable with having no coding history! I don't think he realises that it's not complete, and he doesn't code himself either so no idea how he got it to this stage!

    Thanks in advance!


Comments

  • Registered Users Posts: 6,505 ✭✭✭daymobrew


    Could you use Plink - it looks like it comes as part of PuTTY and is intended for automated stuff.


  • Registered Users Posts: 10,634 ✭✭✭✭28064212


    Try changing the LOGIN2 line to:
    Shell.Sendkeys " -l LOGIN2 -o 'StrictHostKeyChecking no' " & IPAdress & VBCrLf
    
    It's bad security practice, but the whole setup is horrible, so it's the least of your worries

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Moderators, Technology & Internet Moderators Posts: 1,335 Mod ✭✭✭✭croo


    daymobrew wrote: »
    Could you use Plink - it looks like it comes as part of PuTTY and is intended for automated stuff.
    Or SCP - Putty SCP


  • Registered Users Posts: 14,026 ✭✭✭✭Potential-Monke


    Cheers folks. I've gone back with the above suggestions! Appreciate the help!


  • Registered Users Posts: 4,473 ✭✭✭FishOnABike


    What response is needed to the "Are you sure?

    Adding a Shell.Sendkeys statement to send the appropriate response and sleep statement between lines 16 and 17 might fix it.


  • Advertisement
  • Registered Users Posts: 14,026 ✭✭✭✭Potential-Monke


    We need a 'yes' to that reply, and then the pw gets entered. Cheers!


  • Registered Users Posts: 10,634 ✭✭✭✭28064212


    What response is needed to the "Are you sure?

    Adding a Shell.Sendkeys statement to send the appropriate response and sleep statement between lines 16 and 17 might fix it.
    Won't work. Or rather, it'll work once and then break again. The question that's being asked is whether you want to connect to a machine that isn't in your known_hosts file. If you answer yes, it'll add that machine's fingerprint to known_hosts, and that machine will then be trusted. Next time you run the script, the question won't be asked

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 14,026 ✭✭✭✭Potential-Monke


    28064212 wrote: »
    Won't work. Or rather, it'll work once and then break again. The question that's being asked is whether you want to connect to a machine that isn't in your known_hosts file. If you answer yes, it'll add that machine's fingerprint to known_hosts, and that machine will then be trusted. Next time you run the script, the question won't be asked

    It's an extra check every time, regardless if it's manual or via the script. So even if you say yes, it will ask every time you access after that.

    I've given the code to the boss to see what he thinks, we've to run it through an internal team before they can give the go ahead for the script to be used by the 8 people it's intended for.


  • Registered Users Posts: 10,634 ✭✭✭✭28064212


    Is the message something like this:
    The authenticity of host '111.222.333.444 (111.222.333.444)' can't be established.
    RSA key fingerprint is f3:cf:58:ae:71:0b:c8:04:6f:34:a3:b2:e4:1e:0c:8b.
    Are you sure you want to continue connecting (yes/no)?
    
    If so, then it's supposed to add the key to the known_hosts file when you answer yes the first time. If it keeps asking, it means there's a permissions issue on the 192 machine.

    So long as you're sure the permission issue will never be fixed, then you can just change the script to:
    ...
    Shell.Sendkeys "PW1" & VBCrLf
    wscript.sleep(1000)
    Shell.Sendkeys "ssh -l LOGIN2 " & IPAdress & VBCrLf
    wscript.sleep(1000)
    Shell.Sendkeys "yes" & VBCrLf
    wscript.sleep(1000)
    Shell.Sendkeys "PW2" & VBCrLf
    wscript.sleep(1000)
    output = Shell.Run("notepad.exe T:\path to file.txt")
    
    Although the 'StrictHostKeyChecking no' option should also work and be faster (one fewer sleep statement)

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 14,026 ✭✭✭✭Potential-Monke


    Awesome, thanks! That's the exact message. So I put in the lines you added, and it passed the yes/no, told me it was permanently added to the host file, but then didn't accept PW2. Tried to log in without the LOGIN2/PW2 automatically, and it's not taking my password so something else is happening right now, so can't check to see if being permanently added is something it's supposed to do (even though it is supposed to, but I don't think it ever did previously).

    Think I need to just send this back and let them figure it out. Don't want to be doing things I'm not supposed to!


  • Advertisement
Advertisement