when netcat act as telnet client, it becomes better.

April 21st, 2007 mysurface Posted in Admin, nc | Hits: 62518 | 3 Comments »

I have an experience on using netcat (nc) as telnet client which I would like to share about this discovery. I have heard few of my friends saying, netcat can be a “hacker” tool, it is also known as “Swiss army knife”. It is true, netcat can transform into a server, a various of tcp client, a port scanner, chat medium, file transfering, remote control etc. You can have some of these tips at byexamples.com or have a look at this tutorial.

First of all why I wants to use netcat as telnet client instead of telnet command itself? What is my needs that telnet client doesn’t provides?

To connect to some routers, switches, we usually use telnet client. We probably want to extract some info out from the connected switches or routers. Or we probably wants to run some repetitive routines as well. I have to connect to a TelcoBridges switch using telnet. I was required to extract the information for debugging reference by running some commands after get connected.

I have to do it manually, I need to login to the switch like this, (assume the IP of the switch is 192.168.1.199):

telnet 192.168.1.199

After that, it will returns a prompt such as $, and I have to type the command one by one. Consequently, I have to manually copy and paste the results from terminal to a file. It is tedious, and it waste me almost 20 minutes to complete the routine every time I needed the information.

Therefore, I start to search for a solution that allows me feed the commands through telnet with a single line of command. I am trying the line bellow and it does NOT work in this way.

telnet 192.168.1.199 <<<"print_debug" 

It will be ended without giving me requested results.

Out of sudden, netcat comes to my mind, and It works!

nc 192.168.1.199 23 <<<"print_debug" 

As netcat is a general tool, therefore you need to specified port number to it. Port 23 is for telnet. Further more I need to store the result into a file.

nc 192.168.1.199 23 <<<"print_debug" > result.txt 

But this makes netcat stay open and cannot be kill by control-C, pkill may does the killing but I have a better solution for that. Another thing is, I want to run more than one commands besides just print_debug.

Bellow is my solution:
First, Create a normal text file and list all the commands line by line. At the end of the line put ‘exit’, Assume my file is call commands.txt. Examples:

print_debug
proplist
...
exit
 

Secondly, I can reconstruct my netcat command line into this

nc 192.168.1.199 23 < commands.txt >results.txt 

Thats it! You just need to define your commands once and you can execute the netcat line. Within a second, your result will be generated.

I think this should be works for other switches or routers. If you make it works on other switches besides telcobridges, please leaves a comment let us know.

[tags] netcat, telnet, telcobridges, configuration, switches, routers [/tags]

3 Responses to “when netcat act as telnet client, it becomes better.”

  1. I really must thank for your blog, i’m a regular reader and i usually learns something i will actually use when i read it… :) Great work!!! (My website is in swedish, so don’t bother ;) )

  2. Somebody necessarily lend a hand to make seriously articles I might state. This is the first time I frequented your web page and to this point? I amazed with the analysis you made to make this actual submit amazing. Great activity!

  3. What a material of un-ambiguity and preserveness of valuable experience
    concerning unpredicted feelings.

Leave a Reply