LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-29-2012, 09:33 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
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?
 
Old 12-29-2012, 11:36 AM   #2
bijo505
Member
 
Registered: Nov 2012
Location: Bangalore
Distribution: Fedora & Ubuntu
Posts: 77

Rep: Reputation: 18
Quote:
Originally Posted by figure20012 View Post
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
 
1 members found this post helpful.
Old 12-29-2012, 01:26 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 2,199

Rep: Reputation: 567Reputation: 567Reputation: 567Reputation: 567Reputation: 567Reputation: 567
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
 
3 members found this post helpful.
Old 12-30-2012, 01:53 AM   #4
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
thnx a lot for helping
 
  


Reply

Tags
bash, telnet


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Net::Telnet with no prompt Fredde87 Programming 4 09-16-2008 07:33 PM
change Telnet login prompt Joshsawyer77 Linux - Newbie 4 07-01-2006 04:50 AM
telnet delays before login prompt laxu Linux - General 2 07-02-2004 01:39 AM
no login prompt in telnet bilal.shaikh Linux - Newbie 1 11-13-2003 12:02 PM
telnet connects but login prompt does not appear jhess Linux - Software 2 10-10-2003 06:05 AM


All times are GMT -5. The time now is 01:19 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration