telnet script

Hi,

I need a script that take one parameter as destination hostname and two parameter as ranges and tries telnet and records the successful connections.

fo reg:

./testtelnet.sh destination-host 1000 1050

should give me all the port between 1000 and 1050 what successfully connected to destination.

Regards,
Mohtashim

sort of a port scan?

Have you looked at nmap?

nmap
bash: nmap: command not found

I do not have nmap nor do i know what is it for.

./testtelnet.sh destination-host 1000 1050

if I am able to connect on port 1010 to destination-host it should populate in output.

Similarly i wish to give an option to see unsuccessful connection ports only and not the ones that got connected.

telnet of all the possible ways is probably the least useful for this, as you can't set a timeout properly, nor get a meaningful, parseable output. Better would be

  • Installing nmap
  • If that's not possible using netcat/nc, installing it if possible
  • If that's not possible using the socket feature newer versions of bash support
  • And only if nothing of these is useable resort to telnet

Example of how easy it's with netcat/nc:

for port in {1000..1050}; do nc -z -w 3 1.2.3.4 $port && echo "Port $port open" || echo "Port $port closed"; done

you can create a script which will read from a file hostname and port, than you can analyse the string output (refused) or (connected). Make sense?

echo " " | telnet hostame port
nc -vw2 localhost 1000-1050

My server is a production server and I can't installing anything, for I am not the admin and it requires approvals.

Would someone help me with the correct netstat script to figure which ports are connecting and which are not.

Then try using /usr/sfw/bin/openssl s_client -connect HOST_NAME:PORT, this works much better than telnet in Production area, you can have script build around the range of ports that needs to be used with in the script.

Yes, this connects real quick but wait long for blocked remote ports.

How can this be addressed?

If the session takes long, send hup signal and end the session, thats the better option, based on the exit code, term the port as closed or etc etc. But when port is closed , I have seen the command comes to prompt quickly, In your case, I need check why its not happening :wink:

How do we send hup signal inorder to end session.

My OS version is

SunOS mymachine 5.10 Generic_142900-14 sun4v sparc SUNW,T5240