LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2017, 06:28 AM   #1
sknsk
LQ Newbie
 
Registered: Mar 2017
Posts: 12

Rep: Reputation: Disabled
Telnet error- Escape character is '^]' and connection closed by foreign host


In program, I want to telnet the ports present in telnet.txt file and capture screenshot of open ports which is opened on new terminal.

Problems:
1. Escape character is '^]' and Connection closed by foreign host.
2. Loop is not working properly. It only take one ports and closed the connection.

My program:

Code:
readfile()
{
while read -r line
do
name="$line"
echo "$name"
count=$line
xterm -e telnet $line
telnet $line
((count++))
gnome-screenshot xterm -e telnet $line
done < telnet.txt
}
readfile
telnet.txt

Code:
192.168.1.95     1027
192.168.1.95     1028
192.168.1.95     1030
192.168.1.95     2869
192.168.1.95     5357
192.168.1.95     10243
192.168.1.95     135
192.168.1.95     139
192.168.1.95     445
192.168.1.95     554
192.168.1.95     902
192.168.1.95     912
192.168.1.95     1025
192.168.1.95     1026

Output:

Code:
192.168.1.95     1027
Trying 192.168.1.95...
Connected to 192.168.1.95.
Escape character is '^]'.
Connection closed by foreign host.
 
Old 04-10-2017, 07:11 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,212

Rep: Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973Reputation: 3973
telnet can not connect to UDP ports.

Most services use a binary protocol and do not reply when "probed" using telnet. For others that are ASCII like http or smtp you need to enter a command before you will see a response from the server.

There really isn't anything to capture.
 
Old 04-10-2017, 08:18 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,590

Rep: Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918Reputation: 1918
Quote:
Originally Posted by sknsk View Post
2. Loop is not working properly. It only take one ports and closed the connection.

That's because telnet is reading all the input you've redirected for the loop, prevent that by redirecting from /dev/null

Code:
telnet $line </dev/null
See also, similar issue with ssh.
 
1 members found this post helpful.
Old 05-01-2017, 04:14 PM   #4
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
Are you sure the host is listening to port 23?
 
Old 05-02-2017, 05:46 AM   #5
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 698

Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by Laserbeak View Post
Are you sure the host is listening to port 23?
He is telnetting to another port (a pretty basic, simple and common way to check if a port on a server can be reached)

Telnet's syntax is "telnet <host> <port>"; none of his ports are 23 :-)
 
Old 05-02-2017, 12:04 PM   #6
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
Quote:
Originally Posted by Ramurd View Post
He is telnetting to another port (a pretty basic, simple and common way to check if a port on a server can be reached)

Telnet's syntax is "telnet <host> <port>"; none of his ports are 23 :-)
Yes, I know that -- I guess I didn't read the post very well and was too quick to answer. Actually, that response from telnet does indicate the port is open, you'd get a different output if it wasn't accepting connections on it. You're just not sending the data the daemon expects, so it's closing the connection.

Last edited by Laserbeak; 05-02-2017 at 12:07 PM.
 
  


Reply


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
telnet to a port on RHEL 6 : Connection closed by foreign host after a few seconds linuxuser26 Linux - Networking 1 08-11-2015 03:07 PM
Telnet localhost 465, pop3s, imaps. connection closed by foreign host tuanhqit Linux - Newbie 4 08-12-2014 05:49 PM
Telnet: Connection closed by a foreign host DBrenchley Linux - Server 3 05-16-2014 12:49 AM
telnet - connection closed by foreign host rbumann Linux - General 11 01-05-2012 08:43 AM
Telnet error "Connection closed by foreign host" without prompting login. jhilton Linux - Newbie 1 06-25-2008 06:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration