Last active
August 8, 2019 07:12
-
-
Save VeggieVampire/c4d2897a2d5a379bf1aecdad71434cc0 to your computer and use it in GitHub Desktop.
This is an expect script that establishes a connection to the IP and port you give it to check connectivity from a remote host.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
#set multiPrompt {[#>$] } | |
#exp_internal 1 | |
set NODE [lindex $argv 0]; | |
set IPz [lindex $argv 1]; | |
set Portz [lindex $argv 2]; | |
set Passwdz [lindex $argv 3]; | |
#log_file -noappend output.log | |
set timeout 1 | |
set force_conservative 0 ;# set to 1 to force conservative mode even if | |
if {$force_conservative} { | |
set send_slow {1 .1} | |
proc send {ignore arg} { | |
sleep .1 | |
exp_send -s -- $arg | |
} | |
} | |
spawn ssh -q $NODE | |
expect { | |
"assword:" { send -- "$Passwdz\r" } | |
"$" { puts "At Promt " } | |
} | |
send -- "telnet $IPz $Portz" | |
expect { | |
"Trying..." { puts "Trying..." } | |
"character" { puts "You are Connected" } | |
} | |
send -- "\x1D" | |
send -- "\x1D" | |
send -- "quit\r" | |
send -- "quit\r" | |
send -- "quit\r" | |
expect { | |
"Connection closed." { puts "telnet connection closed." } | |
"$" { puts "At Promt " } | |
} | |
send "exit\r" | |
expect eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./telnet_connectivity_check.exp RemoteHostName ClientIP ClientPort PASSWORD|grep Connected
or use without a password if you have ssh keys setup
./telnet_connectivity_check.exp RemoteHostName ClientIP ClientPort |grep Connected
much cooler scripts for the same purpose.
https://stackoverflow.com/questions/4922943/test-if-remote-tcp-port-is-open-from-a-shell-script/19866239