Jump to content
Sign in to follow this  
moraist

PuTTY Security Alert

Recommended Posts

moraist

Hi Guys,

I am new in the AutoIT language and I am trying to create a script using PuTTY to make some change in the network devices, such as switches and routers.

The script is working, but sometimes it is stopping by itself because of the PuTTY's Security Alert pop-up.

I already tried fix this problem but I not got success until now, I just need click "Sim" button and run comammds in the PuTTY session. Which the best way to handle the PuTTY Pop-Up?

This is my script:

#include <file.au3>
#include <Array.au3>

$ipFile = FileOpen("C:\Tools\ips.txt", 0)
$ipFailed = FileOpen("C:\Tools\Failed.txt", 1)
$pingFailed = FileOpen("C:\Tools\pingFailed.txt", 1)
$ipSuccess = FileOpen("C:\Tools\Success.txt", 1)

Local $user = InputBox("Credentials", "Enter the username")
Local $pass = InputBox("Credentials", "Enter the password")

$app = ("putty.exe -l" & " " & $user & " " & "-pw" & " " & $pass)

If FileGetSize("C:\Tools\ips.txt") = 0 Then
   MsgBox(0, "ERROR", "The file is empty!")
Else
   While 1
      $ipaddr = FileReadLine($ipFile)
      If @error = -1 Then ExitLoop
         $iPing = Ping($ipaddr, 1)
         If $iPing = 0 Then
            FileWrite($pingFailed, $ipaddr & @CRLF)
         Else
            $statusSVC = RunWait("portqry.exe -n " & $ipaddr & " -e 22 " & " -q")
            If $statusSVC = 1 Then
               FileWrite($ipFailed, $ipaddr & @CRLF)
            Else
               $conn = Run (@ComSpec & " /c " & $app & ' ' & $ipaddr)
               WinGetHandle($ipaddr & " - PuTTY", "")
               cmd()
               FileWrite($ipSuccess, $ipaddr & @CRLF)
            EndIf
         EndIf
   WEnd
EndIf

Func cmd()
   Sleep(3000)
   Send("conf t")
   Sleep(1000)
   Send("{ENTER}")
   Sleep(2000)
   Send("no username network")
   Sleep(1000)
   Send("{ENTER}")
   Sleep(2000)
   Send("username network privilege 15 secret password-here")
   Sleep(1000)
   Send("{ENTER}")
   Sleep(2000)
   Send("end")
   Sleep(1000)
   Send("{ENTER}")
   Sleep(2000)
   Send("copy run star")
   Sleep(1000)
   Send("{ENTER}")
   Send("{ENTER}")
   Sleep(4000)
   Send("exit")
   Send("{ENTER}")
   Sleep(3000)
EndFunc

FileClose($ipFile)
FileClose($ipFailed)
FileClose($pingFailed)
FileClose($ipSuccess)

 

 

 

 

putty-popup.PNG

Edited by moraist
More details

Share this post


Link to post
Share on other sites
JLogan3o13

Moved to the appropriate forum, as the DEV forum specifically states:

Quote

Do not create AutoIt-related topics here, use AutoIt General Help and Support

@moraist Instead of putty and all the Sends :x have you tried plink?  Check the documentation on plink, specifically the -i parameter, for how to use a local file for your key.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
SlackerAl

It seems like only last week....

Lots of useful links, tips and code examples there. Including setting up key based connections.


Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×