Discussion Locked

Telnet from a KSH or Get the OS Level

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have written a simple program to scan a subnet to see what OS's are running on each machine on that subnet. This is internal to our company. I cannot use snmpinfo as that we don't turn it on, so my only choice is telnet to each machine. Since I'm using a script, I have to wait until the telnet times out before it moves to the next IP address. Problem I have is: the telnet will not timeout on some switchs/routers/hubs or printers and I have to manually kill the telnet before the script will move to the next IP. Anyone know a way to fix this in a ksh script? Or have other suggestions to accomplish this?

7 replies

by radiic

Most unix sh commands return with an error level. Usually most return with 0= success of the command. Maybe you could check and see if telnet returns with errorlevel=0 after about the amount of time that it normally takes to complete a good connect, then you could kill the telnet session if it takes more than x seconds .

Just an Idea.
Rad

by stillatit

Can you use rsh (remsh or rcmd on some systems) instead? This runs ONE command, and returns the result.

Another alternative might be to create a simple batch file which puts the current machine name and OS level into a text file and mails you thetext file. Install this on every machine, set to run out of crontabs however often you need it.

Good luck.

by woodwd234

I'm looking for users with root access to their workstations whom have updated their OS. This means that rsh has generally been disabled and crontabs entries have been removed.

by mdeshon

I'm assuming your program runs on a unix machine. If so, you can send a control-D character to hang up the connection immediately. Try the following line in your program:

echo '^D' | /usr/bin/telnet myhost

you can generate the control-D invi using the control-V command key (i.e. enter 'ctrl-V ctrl-D' to insert a ctrl-D)

Hope this helps,

matt

This discussion is closed to new replies.