Sign in to follow this  
Followers 0
DuncanM

Telnet Automation

17 posts in this topic

I'm looking to automate a telnet session, specifically to log into and send commands to a Cisco device. What would be the best way to go about this with AutoIT (or suggestions if there's a better solution)? I was going to write it in Python, but the library I needed (pexpect) does not work properly in Windows because of a pty requirement.. Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

if you only want to sent commands with telnet then i could write you a little script ^^

you only would have to answer me two questions

1. which commands should be sent?

2. what is a cisco device? ^^

Edited by Schatten

Share this post


Link to post
Share on other sites

if you only want to sent commands with telnet then i could write you a little script ^^

you only would have to answer me two questions

1. which commands should be sent?

2. what is a cisco device? ^^

@Shatten: cisco device is switch or router or any other network device produced by Cisco. It's world known manufacturer. The point of Telnet is to have it working both ways i guess. Doing it only one way will give no usable stuff from automation. At least not what it could be done with it :whistle:


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

if you only want to sent commands with telnet then i could write you a little script ^^

you only would have to answer me two questions

1. which commands should be sent?

2. what is a cisco device? ^^

Actually I'm going to need to not only send commands, but also read the output generated by the telnet session (for example, when the string "Password" appears, send the password).

Share this post


Link to post
Share on other sites

Actually I'm going to need to not only send commands, but also read the output generated by the telnet session (for example, when the string "Password" appears, send the password).

May I ask how you are going to do it?

RK


"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Actually I'm going to need to not only send commands, but also read the output generated by the telnet session (for example, when the string "Password" appears, send the password).

I am not familiar enough with AutoIT to comment on its suitability for this application, but I am aware of several alternatives designed for this application.

I am assuming that you want general purpose scripting ability for Cisco router telnet sessions, and I try to address that with the options below. If you have a specific goal, like backing up your configs, there are tools and pre-written scripts aimed at those specific automation tasks.

Commercial products:

http://www.net-sense.com - Router scripting suite

http://www.solarwinds.net - Various router tools, but likely not exactly what you are looking for.

Open Source/Free:

TCL:

http://www.cisco.com/en/US/products/sw/ios...00801a75a7.html

http://www.oreillynet.com/pub/a/mac/2001/1...router_tcl.html

SNMP:

http://www.pancho.org

Grab-bag:

http://cosi-nms.sourceforge.net/related.html

An end run on this would be using a scriptable terminal emulator:

WRQ Reflections

http://www.wrq.com

Best --Kirk

Edited by DkReaver

Share this post


Link to post
Share on other sites

Might want to look at the TCP commands? Mainly TCPSend().


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

Might want to look at the TCP commands? Mainly TCPSend().

Probably looking at msdn for some dlls would be faster, no?

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Probably looking at msdn for some dlls would be faster, no?

I dont think so.

EDIT::

This seems like easier than looking up a dll.

TCPStartup()
$Socket = TCPConnect("0.0.0.0", 23)
TCPSend($Socket, "Wow!, Im talking on telnet! Sending commands!!!!")
Edited by AzKay

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

the tcp "conversation" could look like this:

cisco device asks for loginname

autoit script sends the loginname

cisco device asks for password

autoit script sends the passwort

cisco device waits for commands

autoit script sends a command

autoit script waits for results

cisco device sends results

close connection

if the cisco device follows this system we only have to translate it to autoit :whistle:

DuncanM it would be the best if you post an example of a telnet session with your cisco device

Edited by Schatten

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I dont think so.

EDIT::

This seems like easier than looking up a dll.

TCPStartup()
$Socket = TCPConnect("0.0.0.0", 23)
TCPSend($Socket, "Wow!, Im talking on telnet! Sending commands!!!!")
lol .. I didn't think it's that easy.

Edit:I will give it a test.

Does anyone know of an open telnet on the internet?

Edited by rbhkamal

"When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix

Share this post


Link to post
Share on other sites

there are many telnet games on the internet

here is one:

server: void.dune.net

Port: 3000

Share this post


Link to post
Share on other sites

An extra telnet programm is not necessary.

You only have to youse the TCPSend () and TCPRecv () function.

Share this post


Link to post
Share on other sites

An extra telnet programm is not necessary.

You only have to youse the TCPSend () and TCPRecv () function.

Sorry, I was out for a few days - thanks for the responses. Anyways, how would I use TCPRecv in this case? Say, for example, I want to wait for the device to return the string "I am returning a string" before sending the command "command" - how would this work?

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Sorry, I was out for a few days - thanks for the responses. Anyways, how would I use TCPRecv in this case? Say, for example, I want to wait for the device to return the string "I am returning a string" before sending the command "command" - how would this work?

you can do this:

while 1
$RECVVAR = TCPRecv ( SOCKET )
if $RECVVAR <> "" then exitloop
wend
Edited by Schatten

Share this post


Link to post
Share on other sites

Hello Duncan,

I like autoit, but for scipting telnet-sessions to cisco-devices I am using TTERMPRO.

I attached 2 examples (rename them to *.TTL).

Frank

show_int.txt

clear_ifcounter.txt

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