Telnet error- Escape character is '^]' and connection closed by foreign host


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Telnet error- Escape character is '^]' and connection closed by foreign host
# 1  
Old 04-10-2017
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 port 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.


Last edited by rbatte1; 04-18-2017 at 12:53 PM.. Reason: Converted textual numbered list to formatted numbered list with LIST=1 tags
# 2  
Old 04-10-2017
Hmm.
Use a here document.
You can change the escape character in telnet - example set to capital letter F
This sets the escape character, connects to some remote node, then exits.
Code:
telnet  << !
set escape F
open $line
F
close
!

Plus, you seem to be making several connections to the same host.

Code:
xterm -e telnet $line
telnet $line
.... 
gnome-screenshot xterm -e telnet $line

# 3  
Old 04-13-2017
Telnet error- Escape character is '^]' and connection closed by foreign host

Still it gives below error. Please help.

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

Output-

Code:
192.168.1.95     1027
telnet>Escape character is 'F'.
telnet>Trying 192.168.1.95...
Connected to 192.168.1.95.
Escape character is 'F'.
Connection closed by foreign host.
telnet> escape character is 'F'.
telnet> (to) usage: open [-l user] [-a] host-name [port]
telnet> telnet> ?Invalid command
telnet> ?Invalid command
telnet> telnet> ?Invalid command
telnet> Need to be connected first for `bye'.


Last edited by sk151993; 04-16-2017 at 08:01 AM..
# 4  
Old 04-18-2017
Please help me if any one has idea about telnet script.
# 5  
Old 04-18-2017
Are you able you connect to the remote host manually in a telnet session? You may want to introduce some split second delays between the telnet commands in your script.
# 6  
Old 04-18-2017
To be honest i don't get the point of some parts of your script. The three lines marked bold make absolutely no sense at all and should be removed from the here-document:

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

Understand that, whatever you put between "<< !" and "!" goes as input/command to your telnet session. Ask yourself if you want to give "xterm -e telnet $line" as a command to your telnet session - most probably not, i suppose. The same goes for "((count++))": what should telnet make of that?

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 7  
Old 04-18-2017
bakunin makes some great points. I did not understand your script either.
You appear to do things that require a shell command line rather than something telnet does.

Instead of telling us how you want to do something, pretend you do not know how to do it. Give us some requirements. Then we can work with you to get what you need.

Example:
I need to graph some data that lives on another machine. But I need to have it run on my desktop machine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Telnet in script Connection closed by foreign host

Hello, I'm trying to learn and automate some tasks via a script, but my first ever script failed with "connection closed by foreign host" error. I checked the other discussions but it didn't help. Could you please help? #!/bin/bash ( sleep 2 echo open x.x.x.x 23 sleep 2 echo user sleep 2... (1 Reply)
Discussion started by: Myrtle
1 Replies

2. Shell Programming and Scripting

Telnet Bash Script (Connection closed by foreign host.)

Hello Everyone, My following script is giving me problems, when the SIP trunk goes down and the telnet session is started and just when the command is about to complete the connection is closed then script restarts. I have noticed that as soon the script types in "sys re" or "sys rebo" or... (6 Replies)
Discussion started by: jeetz
6 Replies

3. Red Hat

Connection closed by host error in rhel 6 Linux

Hi All, I am new to Redhat Enterprise Linux 6 version. I am facing an issue with my lab server which is having RHEL6 lab1:root> uname -a Linux lab1 2.6.32-358.18.1.el6.x86_64 #1 SMP Fri Aug 2 17:04:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux I am getting this error for every 18 minutes 30... (0 Replies)
Discussion started by: go2suresh1979
0 Replies

4. Solaris

"Connection closed by foreign host error" in Solaris 10

Version Details Solaris version : Oracle Solaris 10 8/11 s10x_u10wos_17b X86 $ uname -a SunOS tippy178 5.10 Generic_147441-01 i86pc i386 i86pcThe Issue +++++++++ I have two solaris 10 Virtual Machines created using Virtual Box. One of my applications running on Source was trying to connect... (9 Replies)
Discussion started by: kraljic
9 Replies

5. HP-UX

Connection closed by foreign host

I am trying to connect to my HP server from remote machine. It gets connected but once credential are provided the connection is closed. adroit:/home/seo/hitendra 32 ] telnet myserv1 Trying... Connected to myserv1. Escape character is '^]'. Local flow control on Telnet TERMINAL-SPEED... (4 Replies)
Discussion started by: hiten.r.chauhan
4 Replies

6. Shell Programming and Scripting

shell script/telnet - Remove/Control "Connection closed by foreign host"

How do I gain control of the "Connection closed by foreign host" message telnet yields when you connect to it in a shell script? I'm using the output: #!/usr/local/bin/bash count=$(ping -c 1 $1 | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }') if ; then echo "$1 PING "... (2 Replies)
Discussion started by: phpfreak
2 Replies

7. UNIX for Dummies Questions & Answers

ssh_exchange_identification: Connection closed by remote host Connection closed

Hi Everyone, Good day. Scenario: 2 unix servers -- A (SunOS) and B (AIX) I have an ftp script to sftp 30 files from A to B which happen almost instantaneously i.e 30 sftp's happen at the same time. Some of these sftp's fail with the following error: ssh_exchange_identification: Connection... (1 Reply)
Discussion started by: jeevan_fimare
1 Replies

8. Linux

ssh_ exchange-identification: Connection closed by remote host

Dear All, Recently our server has been giving the error: "ssh_ exchange-identification: Connection closed by remote host" The error causes the server to become in accessible via ssh and the services are stopped/hung. The server has to be restarted to make it working normal again. The... (3 Replies)
Discussion started by: vguleria
3 Replies

9. Shell Programming and Scripting

ssh_exchange_identification: Connection closed by remote host

hi i am trying to connect the frontend server using ssh i got the following error ssh_exchange_identification: Connection closed by remote host can anyone help please (1 Reply)
Discussion started by: Satyak
1 Replies

10. IP Networking

FTP - Connection Closed By Remote Host

Hi, I am having a problem with our AIX 4.3.3 Server accessing FTP. The error is " Connection Closed By Remote Host". Scenario: Since i put a default gateway on the server FTP connection is having a problem but when i remove the default gateway it will works fine.. Is there any way not... (1 Reply)
Discussion started by: mouglybean
1 Replies
Login or Register to Ask a Question