Jump to content

Telnet scripting?


davil
 Share

Recommended Posts

Hi all,

I was wondering how you guys do your telnet scripting? if any?

I.e. we have a lot of jetdirect print servers and cisco switches to administer and I'd like to automate some common tasks and I'd like to be able to request specific info from the switches etc.

I've done a bit of research on this and tried a few different solutions.

One of the things I've tried is the Telnet scripting tool - TST10.exe - http://mike-tech.com/article.php?gif=cisco&article=72 but it no longer has a website and info on it is pretty scant.

I can get it to wait for keystrokes etc. and send keystrokes but it's not like it's a fully fledged scripting/programming language. I need to be able to write a program that can handle any of the possibilities, i.e. if you have to press return at the end of a page of info , and there's five pages of info on one router and only two on another... I'm sure you get what I mean... I'd love to be able to send keystrokes etc. with VBS and the windows scripting host but I'm not sure where to start...

I have found after a lot of searching that maybe I should learn PERL but I am extremely impatient and I just want a quick fix solution and I don't want to have to install yet another compiler or whatever. Plus it's a work thing and I don't have to do it but I'd like to improve my PHP/MYSql based I.T. info system. - we look after 600 PCs here and my colleagues aren't exactly uber-hax0rs they're worse than me so I had to build a web based system that uses aida32/winaudit csv files (saved to a network share) and then a freebasic(like QBASIC) exe that simply converts the CSV into variables that I pass to a .php file on the server via curl which then puts the info into the mysql database, but I also save the CSV to the server and the server checks the CSV files against the MYSQL data once a day against what was entered, for security etc. Anyway to cut a long story short I'm keeping to text based stuff rather than the ODBC because a lot of our computers are quite instable, or are running NT4 or whatever...

I can do basic code in PHP, VBS, BATCH and BASIC only (file input/output,string searching,if else,for loops,you know, the easy stuff) but I should be able to turn my hand to most coding as long as it doesn't involve compilers that you need to include libraries and stuff like that. Like C for example... I'm sure C is amazing but I haven't got time to figure out why a simple "HELLO WORLD" app won't compile.

Anyway rant over.... if anybody can help a n00b out he'd much appreciate it.

Link to comment
Share on other sites

Try and find a telnet client with Macro support and create a macro to carry out the commands, etc. We use somethign called the "Attachmate EXTRA! " client at work. Its a full tn3270 telnet client with lots of other options. The site lists something else, so I don't know if it is a newer version or what version we are running at work, but I don't think its the "Extreme" one they have listed on the site. I think it's something like version 6.5 but I do not have it in front of me.

Here is a link to the one on their site, but I think ours is just the 6530 stand alone, and it does nto look quite like this, so maybe this is the newer version? http://www.attachmate.com/en-US/Products/H...xtra-tandem.htm

Link to comment
Share on other sites

Thanks, I'll check that out... it's funny though I just checked out their webpage and the favicon looks a lot like the WRQ one (i.e. WRQ reflections client)  , yep it's the same one... We have the WRQ reflections client 11 here and it has macro support and VBA so I think maybe that's the one to use... I've tried to get into it though and I'm just hitting the start hurdle... If I could get it to do the simplest of things using VB then I could work from there and get it to do exactly what I want but looking through the help and googling gave me nothing.. I'm impatient though so I'll try to have another look. Thanks again.

Link to comment
Share on other sites

Thanks, I'll check that out... it's funny though I just checked out their webpage and the favicon looks a lot like the WRQ one (i.e. WRQ reflections client)   , yep it's the same one... We have the WRQ reflections client 11 here and it has macro support and VBA so I think maybe that's the one to use... I've tried to get into it though and I'm just hitting the start hurdle... If I could get it to do the simplest of things using VB then I could work from there and get it to do exactly what I want but looking through the help and googling gave me nothing.. I'm impatient though so I'll try to have another look. Thanks again.

Well, I know from using the Macro settings in Extra, you just turn it on, do your things, then stop the macro recording. If you then create a batch to start the client it runs the macro on startup(if saved with settings to run macros on startup). You then just AT command it to run and bat script a taskkill to end it when you want to stop it. Extra client can make tons of attached scripted clients that are basically just text files with the setting syou want the clietn to do when started. There are ways to do what your saying with your current setup, but you would probably have to think outside th ebox, and mickey some things together to get the to run close, start at specific times, etc.

Link to comment
Share on other sites

Yep that sounds like a plan alright.. I've tried the WRQ reflections and I recorded a macro and this is what I got:

Sub cisco_test()
' Generated by the Reflection Macro Recorder on 07-20-2007 09:37:01.26.
' Generated by WRQ Reflection for UNIX and Digital 11.0.
    On Error GoTo ErrorHandler

    Dim username As String
    Dim password As String
    Dim password2 As String

    Const NEVER_TIME_OUT = 0

    Dim LF As String    ' Chr$(rcLF) = Chr$(10) = Control-J
    Dim CR As String    ' Chr$(rcCR) = Chr$(13) = Control-M

    LF = Chr$(rcLF)
    CR = Chr$(rcCR)

    username = "OLRO"
    ' Password was removed from this macro for security.
    ' Prompt for (what is assumed to be) a password.
    password = Session.GetPassword( _
        Prompt:="Password:", _
        HostUserName:=username)
    If password = "" Then Exit Sub

    ' Password was removed from this macro for security.
    ' Prompt for (what is assumed to be) a password.
    password2 = Session.GetLoginProperty( _
        Property:="Password2", _
        Prompt:="Password:", _
        HostUserName:=username, _
        Options:=rcIsPassword)
    If password2 = "" Then Exit Sub

    With Session
        If .Connected = False Then
            .ConnectionType = "TELNET"
            .ConnectionSettings = "Host 10.175.1.44"
        End If
        If .Connected = False Then
            .Connect
        End If

        .StatusBar = "Waiting for Prompt: Password:"
        .WaitForString LF & "Password: ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit username
        .CapsLock = False
        .Transmit password, rcDecodePassword
        .Transmit CR

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1>"
        .WaitForString LF & "OL_SRVRM_SW", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""

        ' String omitted because it might change:
        ' .WaitForString "3550_1", NEVER_TIME_OUT, rcAllowKeystrokes

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1>"
        .WaitForString ">", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""

        .CommitLoginProperties
        .Transmit "enable" & CR

        .StatusBar = "Waiting for Prompt: Password:"
        .WaitForString LF & "Password: ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit password2, rcDecodePassword
        .Transmit CR

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString LF & "OL_SRVRM_SW", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""

        ' String omitted because it might change:
        ' .WaitForString "3550_1", NEVER_TIME_OUT, rcAllowKeystrokes

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString "#", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""

        .CommitLoginProperties
        .Transmit "show mac-address-table" & CR

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit CR

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit CR

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit CR

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: --More--"
        .WaitForString LF & " --More-- ", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit " "

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString LF & "OL_SRVRM_SW", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""

        ' String omitted because it might change:
        ' .WaitForString "3550_1", NEVER_TIME_OUT, rcAllowKeystrokes

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString "#", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit "                                                  " & CR

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString LF & "OL_SRVRM_SW", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""

        ' String omitted because it might change:
        ' .WaitForString "3550_1", NEVER_TIME_OUT, rcAllowKeystrokes

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString "#", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit CR

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString LF & "OL_SRVRM_SW", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""

        ' String omitted because it might change:
        ' .WaitForString "3550_1", NEVER_TIME_OUT, rcAllowKeystrokes

        .StatusBar = "Waiting for Prompt: OL_SRVRM_SW3550_1#"
        .WaitForString "#", NEVER_TIME_OUT, rcAllowKeystrokes
        .StatusBar = ""
        .Transmit "logout" & CR
        ' .WaitForString LF & "<Your 'TELNET' connection has terminated>" & CR & LF & LF, NEVER_TIME_OUT, rcAllowKeystrokes
    Exit Sub

ErrorHandler:
    .MsgBox Err.Description, vbExclamation + vbOKOnly

    End With
    ' Recording stopped at 09:38:38.64.
End Sub

as you can see above it doesn't store the password (I know that's bad practice anyway) but I kinda need that facility... I presume I can add it in to the VB but to be honest I think I'm gonna need a one exe solution, none of this installing Reflections crap.... but we will see. I suppose putting reflections on the web server and getting it to do all the work from there.... I suppose I'm gonna have to brush up on me VB so...

p.s. - Is "Extra" free? I doubt it.

Link to comment
Share on other sites

The Extra client is not free. Or at least the one we use, but I think they have "evaluation" copies on the site. :wink:

We use an older version at work to connect to our mainframe, and I am not sure if that version can even be bought or just found online somewhere, but there are probably free or open source programs that will do the same thing.

Link to comment
Share on other sites

Looks like I'm gonna go back to what I usually do and have a look at AUTOIT etc.

AUTOIT - http://www.autoitscript.com/autoit3/

autohotkey - http://www.autohotkey.com/This is a line of text in the notepad window

cmdret - http://www.autohotkey.com/forum/topic8606.html

and just send keys to either putty or telnet or something and wait etc...

I'll post up more info if I'm successful

Link to comment
Share on other sites

Ok I've decided on AUTOIT3 and Telnet - it seems to work fine... this is to run on one Machine only anyhow so I have no compatibility issues

It seems to be working well and capturing all the stuff I need to a text file which I can parse easily with PHP - I'll post up all the code when I am finished..

Kermit looks nice though but I can't get my hands on it here as it costs money

http://www.columbia.edu/kermit/k95.html

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...