LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Another one . . . . telnet: connect to address 127.0.0.1: Connection refused (https://www.linuxquestions.org/questions/linux-networking-3/another-one-telnet-connect-to-address-127-0-0-1-connection-refused-900760/)

verWire3619 09-02-2011 12:48 PM

Another one . . . . telnet: connect to address 127.0.0.1: Connection refused
 
CentOS release 5.5 (Final)

I'm not new to linux, but very new to networking. I apologize. I'm sure there's prob an answer, but I'm not sure what I'm looking at.

I have this expect script:
Code:

#!/usr/bin/expect -f

exp_internal 1

set stp [lindex $argv 0]
set logfile [lindex $argv 1]

set timeout 1800
spawn /usr/local/bin/$stp
match_max 100000
expect -exact "Trying"
expect -exact "Connected to"
expect -exact "Escape character is '^\]'.\r\r
"
expect -exact "Select a terminal from the list below:"
sleep 2
send -- "23\r"
expect -exact "Connection established as terminal"
sleep 2
send -- "login:uid=userid\r"
expect -exact "Enter Password :"
send -- "passwd\r"
expect -exact "User logged in on terminal"
expect -exact ";\r"
sleep 2
log_file -noappend $logfile
send -- "rtrv-slk\r"
expect -exact "Command Accepted"
expect -exact "SLK table is"
expect -exact ";\r"
log_file
sleep 2
send -- "logout\r"
expect -exact "Command Completed."

send -- ""
expect -exact "\r
telnet> "
send -- "close\r"
expect eof

/usr/local/bin/$stp looks like this
Code:

#!/bin/bash

FLOOR=1024

lport=0  #initialize
while [ "$lport" -le $FLOOR ]
do
  lport=$RANDOM
done
echo "Generating random local port ---  $lport"
echo "IMPORTANT:  Use Ctrl-] , close to exit"
echo

/usr/bin/ssh -f -N -L $lport:127.0.0.1:23 ncstp
sleep 1
/usr/bin/telnet localhost $lport

I turned diagnostic tracking on in the expect script and got:
Quote:

spawn /usr/local/bin/gotostpnc
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {13443}

expect: does "" (spawn_id exp6) match exact string "Trying"? no
Generating random local port --- 28154

expect: does "Generating random local port --- 28154\r\n" (spawn_id exp6) match exact string "Trying"? no
IMPORTANT: Use Ctrl-] , close to exit


expect: does "Generating random local port --- 28154\r\nIMPORTANT: Use Ctrl-] , close to exit\r\n\r\n" (spawn_id exp6) match exact string "Trying"? no
ssh_exchange_identification: Connection closed by remote host

expect: does "Generating random local port --- 28154\r\nIMPORTANT: Use Ctrl-] , close to exit\r\n\r\nssh_exchange_identification: Connection closed by remote host\r\r\n" (spawn_id exp6) match exact string "Trying"? no
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused

expect: does "Generating random local port --- 28154\r\nIMPORTANT: Use Ctrl-] , close to exit\r\n\r\nssh_exchange_identification: Connection closed by remote host\r\r\nTrying 127.0.0.1...\r\r\ntelnet: connect to address 127.0.0.1: Connection refused\r\n" (spawn_id exp6) match exact string "Trying"? yes
expect: set expect_out(0,string) "Trying"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Generating random local port --- 28154\r\nIMPORTANT: Use Ctrl-] , close to exit\r\n\r\nssh_exchange_identification: Connection closed by remote host\r\r\nTrying"

expect: does " 127.0.0.1...\r\r\ntelnet: connect to address 127.0.0.1: Connection refused\r\n" (spawn_id exp6) match exact string "Connected to"? no
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) " 127.0.0.1...\r\r\ntelnet: connect to address 127.0.0.1: Connection refused\r\n"
expect: spawn id exp6 not open
while executing
"expect -exact "Escape character is '^\]'.\r\r
""
(file "/home/ss7/bin/links.exp" line 13)
This expect script is in a loop in a perl script for 4 network elements. I'm able to make connection to 2 of the 4 elements. This was working at one time.

I do not know what changed.
I'm not sure where to begin to troubleshoot.

Any guidance is much appreciated.

Thanks!

thesnow 09-02-2011 01:14 PM

Your ssh connection is failing, I'd start by troubleshooting an ssh connection straight to one of the machines you're having issues with and increase ssh verbosity (-vvv). If you Google for your error message, "ssh_exchange_identification: Connection closed by remote host", you may find other insight.

verWire3619 09-02-2011 01:49 PM

Thank you!

So I ran the following 2 commands:

Quote:

% /usr/bin/ssh -v -f -N -L 28154:127.0.0.1:23 ncstp
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to ncstp [10.48.8.16] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
ssh_exchange_identification: Connection closed by remote host
Quote:

% /usr/bin/ssh -v -f -N -L 28154:127.0.0.1:23 nestp
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to nestp [10.48.12.16] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version TF1-SSH-VX-2.0.0-i005
debug1: no match: TF1-SSH-VX-2.0.0-i005
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'nestp' is known and matches the DSA host key.
debug1: Found key in /root/.ssh/known_hosts:57
debug1: ssh_dss_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentication succeeded (none).
debug1: Local connections to LOCALHOST:28154 forwarded to remote address 127.0.0.1:23
debug1: Local forwarding listening on 127.0.0.1 port 28154.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on ::1 port 28154.
debug1: channel 1: new [port listener]
debug1: Entering interactive session.


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