9 Replies - 769 Views - Last Post: 13 September 2013 - 01:15 AM Rate Topic: -----

#1 CodeCapition1  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Telnet automation

Posted 03 August 2013 - 06:23 AM

i have been using tenlet to issue commands to networked devices for a few months now. i have been looking for resources to help me automate the task for a while but i have been unsuccessful, most of the help i find is to log into a router or some such device and do tasks like update IP information or to log the session when you have to say update settings or something, basically most of what i have found didnt seem like it was close enough to what i was doing to help me out much so im going to ask around here a bit and see if someone could point me in the right direction.

here is what i do i would like to automate:
first i connect a factory defaulted device to my local machine via ethernet.
then i open a command prompt window or terminal depending on which machine i happen to be using that day.
next in windows i would type something like "telnet open 192.168.1.20"
then i will issue a few "Poke" commands (not sure if poke is a device specific command or not)
they look something like this- "poke 123e98 00010001"
i will normally issue between 5 and 7 commands like that to the device depending on which type it is
then i just navigate to a specific web page to save the changes i have made and reboot the device.

fairly simple and easy, yes.
i would like to make some sort of script or something that will automate connecting to my device and sending the commands and if possible once the commands are sent to open a browser and do the navigation for me.
i know i may not be able to make one script or whatever that will work for every device i may need to make 3 or 4 different ones to get this done. but if someone has some pointers or maybe like somewhere to get an idea of where i need to start cause im lost and every resource i have found i have not had any luck with yet. i have tried one utility called "expect" but alas could not get anything useful to come of it. any help would be greatly appreciated

Also im not sure if this is posted where it should be so sorry if i didnt get it right

Is This A Good Question/Topic? 0
  • +

Replies To: Telnet automation

#2 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,850
  • Joined: 10-May 07

Re: Telnet automation

Posted 03 August 2013 - 06:43 AM

You should be able to script this. Depending on the language... there are different ways to interpret dynamics. That being, I would write a function within the script, pass the ip to the script, read in argument 1 of the script, & telnet to that address. Write the code to be reusable.

** Moved to 'other languages' **
Was This Post Helpful? 1
  • +
  • -

#3 CodeCapition1  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: Telnet automation

Posted 03 August 2013 - 07:20 AM

here is what i have so far and what error it gives me:

#!/bin/bash
#Canopy Poke SM to advantage AP
telnet 169.254.1.1 <<EOF
poke 283a78 32303330/r
poke 264e9c 20300000/r
poke 283a44 20300000/r
poke 286798 20300000/r
poke 2864b8 01000000/r
EOF



upon execution the terminal returns this message:

Trying 169.254.1.1...
Connected to 169.254.1.1.
Escape character is '^]'.
Connection closed by foreign host.

can anyone tell me why this is not working maybe
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,850
  • Joined: 10-May 07

Re: Telnet automation

Posted 03 August 2013 - 09:07 AM

169.254.1.1 is not a valid ip address. What happens when you manually telnet to this address?

Generally 169.254.x.x is reserved for a 'self-assigned' address when dhcp times out.
Was This Post Helpful? 1
  • +
  • -

#5 CodeCapition1  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: Telnet automation

Posted 03 August 2013 - 09:25 AM

I understand the IP is not valid for actual networking, but the issue is not the IP. when I manually do it it works just fine. What it is is a proprietary device with a factory default IP address of 169.254.1.1 from the factory I have to use that address to access the device and generally we set static IP's in the device once it's configured for live use. We normally use a 172.22.x.x addresses once we hook a device up to our network. So I appreciate your thourgouh-ness in identifying something that could be an issue. But the address we use to access the device is a169 but we could just as easily set it to 192.168.1.87 or 23.45.76.123 or whatever we need it to be. So I still feel my issue is with the syntax of the script I'm trying to use or just not using the right method or something. I was thrown at this task a few months ago and had our head network engineer write a few scripts that automate configuring these devices like for example imagine you are an ISP. And the moden you buy to install in people's homes comes from the factory with said IP of 169.254.1.1 and you generally will open up a browser and navigate to that IP to access the GUI and change settings from factory default to what settings it takes to make it function on your network. Now I'm working on automating the task of changing the devices hard coded protocols from a 20mb limit to say a50mb limit using one set of "poke"commands or to 100mb limit with configuration changes for commercial use instead of residential use using a different set depending on what device we need to change it to. We use SNMP to automate configuration changes but I would like a script to make protocol changes more automatic.
Sorry for such a long response but I feel if the situation is understood a little better it may help
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,850
  • Joined: 10-May 07

Re: Telnet automation

Posted 03 August 2013 - 09:33 AM

When you telnet to it manually, do you use port 23? That should be the default port. Your script doesn't specify a port, so it is going to use 23 as well.

oh, try this, Your sending everything in one line using that script :

#!/bin/bash
#Canopy Poke SM to advantage AP
telnet 169.254.1.1
sleep 5
echo poke 283a78 32303330/r
echo poke 264e9c 20300000/r
echo poke 283a44 20300000/r
echo poke 286798 20300000/r
echo poke 2864b8 01000000/r



Now this is a very stupid script, we don't want to use the sleep command, but it should prove as a proof of concept.
Was This Post Helpful? 1
  • +
  • -

#7 CodeCapition1  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: Telnet automation

Posted 03 August 2013 - 09:36 AM

Nope doing it manually I just type In my terminal
"Telnet"
"Open 169.254.1.1"
And then my poke commands.
I would assume if a script could connect to ant telnet-able device without the need for login creds and could issue the commands like I was typing at my keyboard it would suffice. But obviously in my cases I can't even get that far.
Was This Post Helpful? 0
  • +
  • -

#8 CodeCapition1  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: Telnet automation

Posted 05 August 2013 - 05:33 AM

ok so adding the "sleep 5" command on line 4 did help but not much now it connects to the device and will display the same "hello" screen i get when i do it manually, but fails to send the poke command to the remote device it just waits there till i type it manually which it will let me do. but if i tell it to exit once the connection to the device closes it will "echo" the poke to the terminal screen as shown below:

localuser@localhost Update$ ./sm_ap.sh

Trying 169.254.1.1...
Connected to 169.254.1.1.
Escape character is '^]'.

/---------\
C I S C O  

Cisco Wireless Technology Center
(Copyright 2001-2005 Cisco Inc.)

Telnet+> exit
Connection closed by foreign host.
poke 283a78 32303330
poke 264e9c 20300000
poke 283a44 20300000
poke 286798 20300000
poke 2864b8 01000000

localuser@localhost Update$



i manually typed "exit" so the script would continue on about its business.
i have tried to pipe "|" the poke commands to the telnet connection, i have tried it indivudally with each command and with all 5 at once, i have tried some "netcat" command i found in one search i was doing. i have tried a few different things but keep getting the same results, telnet connected but failure to send the commands to the device. im starting to think i may be stuck doing this task manually everytime im going to look in to expect a little more after spending some time reading about it i think it may be able to accomplish what i need it to
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,850
  • Joined: 10-May 07

Re: Telnet automation

Posted 05 August 2013 - 06:47 AM

Try removing the slash r from the poke commands. You should not need to force a return on a script.
Was This Post Helpful? 0
  • +
  • -

#10 Gorian  Icon User is offline

  • ninja DIC
  • member icon

Reputation: 120
  • View blog
  • Posts: 1,681
  • Joined: 28-June 08

Re: Telnet automation

Posted 13 September 2013 - 01:15 AM

Possibly relevent, I have a tutorial I have written on automating telnet in BASH
http://www.dreaminco...doc-and-expect/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1