Sign in to follow this  
Followers 0
Guest DGi

telnet via AutoIT

6 posts in this topic

I am trying Automate Synchronize Clocks on our network device.

Because the devices haven't NTP protocol i decide write script.

The only one communication way with the devices is telnet.

I wrote following script

;Open TELNET SERVER PORT

RUN ("cmd.exe")
Sleep(1000)
SEND ('telnet '& $CmdLine[1] &' '& $CmdLine[2] &' {ENTER}')

; User 
Sleep(1000)
Send("root{ENTER}")

; Password
Sleep(3000)
Send("letmein{ENTER}")

; Synchronize the CLOCKs 
Sleep(3000)
Send('date '& @MDAY &' '& @MON &' '& @YEAR &' '& @HOUR &' '& @MIN &' '& @SEC &'')
Sleep(1000)
Send("{ENTER}")

; EXIT
Send("exit{ENTER}")

; Close Window 
WinClose ('Telnet '& $CmdLine[1] &'')
WinWaitClose ('Telnet '& $CmdLine[1] &'')

The script works, but i would like make few additional checks:

1. Verify if the script ran with two parameters - if not send "net send msg"

Why it isn't work ?

If $CmdLine[2] ="" Then
   RUN ("cmd.exe")
Sleep(1000)
SEND (net send)
EndIf

2. Verify if telnet session is successfully connected - if not send "net send msg"

Any idea ?

Thanks

Share this post


Link to post
Share on other sites



Try this for the paramter check:

If $CmdLine[0] <> 2 Then
  $cmd = "C:\WINNT\System32\Cmd.exe"
  Run ($cmd,"", @SW_SHOW)
  WinWait($cmd, "")
  ControlSend($cmd,"","","net send ...")
EndIf

Greetings,

ZeD

Share this post


Link to post
Share on other sites

Have you thought of using a third party program? If not you may want to check one out. It syncronizes your clock with the atomic clock.

World Time Server

Hope you get something figured out,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Have you thought of using a third party program? If not you may want to check one out. It syncronizes your clock with the atomic clock.

World Time Server

Hope you get something figured out,

JS

<{POST_SNAPBACK}>

thanks but i want syncronize the clocks with my server time

Share this post


Link to post
Share on other sites

Try this for the paramter check:

If $CmdLine[0] <> 2 Then
  $cmd = "C:\WINNT\System32\Cmd.exe"
  Run ($cmd,"", @SW_SHOW)
  WinWait($cmd, "")
  ControlSend($cmd,"","","net send ...")
EndIf

Greetings,

ZeD

<{POST_SNAPBACK}>

thanks,

your code is work,

are you have any idea about verifying telnet session ?

Share this post


Link to post
Share on other sites

I'm not sure. I cannot play with telnet here, because i don't have any telnet servers to connect to. But i guess theres an error-window popping up when connection has failed. Can't you just wait a second and then look up if that error window exists? And if not -> proceed.

Just a thought.

Greetings,

ZeD

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  
Followers 0