LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   telnet without enterin g the telnet prompt bash (http://www.linuxquestions.org/questions/linux-newbie-8/telnet-without-enterin-g-the-telnet-prompt-bash-4175443368/)

figure20012 12-29-2012 09:33 AM

telnet without enterin g the telnet prompt bash
 
i am writing a script to test for open ports using telnet

telnet $server $port
if [ $? -eq 0 ]
echo $port on $server open
fi

but telnet $server $port enters the telnet command prompt

Can anyone please tell me how can i use telnet for not entering the telnet promt?

bijo505 12-29-2012 11:36 AM

Quote:

Originally Posted by figure20012 (Post 4859016)
i am writing a script to test for open ports using telnet

telnet $server $port
if [ $? -eq 0 ]
echo $port on $server open
fi

but telnet $server $port enters the telnet command prompt

Can anyone please tell me how can i use telnet for not entering the telnet promt?

Hi

You can set the escape character by explicitly mention the escape character. After that you can get the exit status.

Eg :1

$echo "q" | telnet -e q localhost 23 2>/dev/null;echo $?
Telnet escape character is 'q'.
Trying 127.0.0.1...
1

Eg: 2

$ echo "q" | telnet -e q localhost 22 2>/dev/null;echo $?
Telnet escape character is 'q'.
Trying 127.0.0.1...
Connected to localhost.
Escape character is 'q'.

telnet> Connection closed.
0
--
Thanks,
Bijo

jpollard 12-29-2012 01:26 PM

You do know there is an utility for that already - its called "nmap".

And nmap can do a lot more than just making telnet connections.

http://nmap.org/book/man.html

figure20012 12-30-2012 01:53 AM

thnx a lot for helping :)


All times are GMT -5. The time now is 11:47 PM.