Sponsored Content
Top Forums Shell Programming and Scripting shell script/telnet - Remove/Control "Connection closed by foreign host" Post 302399416 by phpfreak on Saturday 27th of February 2010 09:41:36 PM
Old 02-27-2010
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:
Code:
#!/usr/local/bin/bash

count=$(ping -c 1 $1 | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ "$count" = "0" ]; then
    echo "$1 PING [FAILED]"
	else
	echo "$1 PING [OK]"
  fi
  
apache=`echo " " | telnet $1 80 | grep Connected | awk '{ print $1 }'`
  if [ "$apache" = "Connected" ]; then
    echo "$1 PORT 80 [OK]"
	else
    echo "$1 PORT 80 [FAILED]"
  fi
ssh=`echo " " | telnet $1 22 | grep Connected | awk '{ print $1 }'`
  if [ "$ssh" = "Connected" ]; then
    echo "$1 PORT 22 [OK]"
	else
    echo "$1 PORT 22 [FAILED]"
  fi
smtp=`echo " " | telnet $1 25 | grep Connected | awk '{ print $1 }'`
  if [ "$smtp" = "Connected" ]; then
    echo "$1 PORT 25 [OK]"
	else
    echo "$1 PORT 25 [FAILED]"
  fi
pop=`echo " " | telnet $1 110 | grep Connected | awk '{ print $1 }'`
  if [ "$pop" = "Connected" ]; then
    echo "$1 PORT 110 [OK]"
	else
    echo "$1 PORT 110 [FAILED]"
  fi


Quote:
*0227|19:45%./simpleservertest.sh host.com
host.com PING [OK]
Connection closed by foreign host.
host.com PORT 80 [OK]
Connection closed by foreign host.
host.com PORT 22 [OK]
Connection closed by foreign host.
host.com PORT 25 [OK]
Connection closed by foreign host.
host.com PORT 110 [OK]
Code:
apache=`echo " " | telnet $1 80 | grep Connected | awk '{ print $1 }'`
echo " " | telnet $1 80 | grep Connected | awk '{ print $1 }'
++ echo ' '
++ telnet host.com 80
++ grep Connected
++ awk '{ print $1 }'
Connection closed by foreign host.
+ apache=Connected
  if [ "$apache" = "Connected" ]; then
    echo "$1 PORT 80 [OK]"
        else
    echo "$1 PORT 80 [FAILED]"
  fi
+ '[' Connected = Connected ']'
+ echo 'host.com PORT 80 [OK]'
host.com PORT 80 [OK]

But DeBug doesn't help me to understand why? Smilie
 

10 More Discussions You Might Find Interesting

1. Cybersecurity

"421 service not available, remote server has closed connection."?

"421 service not available, remote server has closed connection." I tried to do ftp to one of the unix server . ftp hostname password It get connects when i do any command it throws error ftp> ls "421 service not available, remote server has closed connection." (1 Reply)
Discussion started by: vishaldsh
1 Replies

2. 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

3. UNIX for Advanced & Expert Users

"Connection closed by remote host" while doing ssh to a solaris box

Hi All, When i try to do ssh from a linux to solaris box its throughing "Connection closed by remote host". Please not that this error is not occuring every time i do ssh, it occurs at random timing( Mostly ssh is successful) - unfortunately my script which is doing ssh is falling at this time... (4 Replies)
Discussion started by: pkumar7
4 Replies

4. Solaris

"Connection closed by" error

OS: Solaris 8 Sparc server1:userA:/home/userA# ssh userB@server1 Connection closed by < IP address> Problem: From being a userA, I am unable to connect/ssh to the same server as when trying to use a different account. (userB) Do you know where can i start checking? Here are some... (3 Replies)
Discussion started by: hrist
3 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. 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

7. UNIX for Dummies Questions & Answers

What is the significance of sh -s in ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh?

Please can you help me understand the significance of providing arguments under sh -s in > ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh (4 Replies)
Discussion started by: Sree10
4 Replies

8. 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

9. Shell Programming and Scripting

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: Escape character is '^]' and Connection closed by foreign host. Loop is not working properly. It only take one ports and closed the connection. ... (9 Replies)
Discussion started by: sk151993
9 Replies

10. 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
SHOREWALL6-TCFILTER(5)						  [FIXME: manual]					    SHOREWALL6-TCFILTER(5)

NAME
tcfilters - shorewall6 u32 classifier rules file SYNOPSIS
/etc/shorewall6/tcfilters DESCRIPTION
Entries in this file cause packets to be classified for traffic shaping. Beginning with Shorewall 4.4.15, the file may contain entries for both IPv4 and IPv6. By default, all rules apply to IPv6 but that can be changed by inserting a line as follows: IPV4 Following entries apply to IPv4. IPV6 Following entries apply to IPv6 ALL Following entries apply to both IPv4 and IPv6. Each entry is processed twice; once for IPv4 and once for IPv6. The columns in the file are as follows (where the column name is followed by a different name in parentheses, the different name is used in the alternate specification syntax). CLASS - interface:class The name or number of an interface defined in shorewall6-tcdevices[1](5) followed by a class number defined for that interface in shorewall6-tcclasses[2](5). SOURCE - {-|address} Source of the packet. May be a host or network address. DNS names are not allowed. DEST - {-|address}} Destination of the packet. May be a host or network address. DNS names are not allowed. PROTO - {-|protocol-number|protocol-name|all} Protocol. DEST PORT (dport) - [-|port-name-or-number] Optional destination Ports. A Port name (from services(5)) or a port number; if the protocol is icmp, this column is interpreted as the destination icmp-type(s). SOURCE PORT (sport) - [-|port-name-or-number] Optional source port. TOS - [-|tos] Optional - specifies the value of the TOS field. The tos value can be any of the following: o tos-minimize-delay o tos-maximuze-throughput o tos-maximize-reliability o tos-minimize-cost o tos-normal-service o hex-number o hex-number/hex-number The hex-numbers must be exactly two digits (e.g., 0x04)x. LENGTH - [-|number] Optional. Must be a power of 2 between 32 and 8192 inclusive. Packets with a total length that is strictly less than the specified number will match the rule. EXAMPLE
Example 1: Place all 'ping' traffic on interface 1 in class 10. Note that ALL cannot be used because IPv4 ICMP and IPv6 ICMP are two different protocols. #CLASS SOURCE DEST PROTO DEST # PORT IPV4 1:10 0.0.0.0/0 0.0.0.0/0 icmp echo-request 1:10 0.0.0.0/0 0.0.0.0/0 icmp echo-reply IPV6 1:10 ::/0 ::/0 icmp6 echo-request 1:10 ::/0 ::/0 icmp6 echo-reply FILES
/etc/shorewall6/tcfilters SEE ALSO
http://shorewall.net/traffic_shaping.htm http://shorewall.net/MultiISP.html http://shorewall.net/PacketMarking.html NOTES
1. shorewall6-tcdevices http://www.shorewall.net/manpages6/shorewall6-tcdevices.html 2. shorewall6-tcclasses http://www.shorewall.net/manpages6/shorewall6-tcclasses.html [FIXME: source] 06/28/2012 SHOREWALL6-TCFILTER(5)
All times are GMT -4. The time now is 01:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy