Skip to content

Instantly share code, notes, and snippets.

@nimatrueway
Created December 18, 2020 19:28
Show Gist options
  • Save nimatrueway/968f1a37ca15ac6aef9bcf9be1b8aea5 to your computer and use it in GitHub Desktop.
Save nimatrueway/968f1a37ca15ac6aef9bcf9be1b8aea5 to your computer and use it in GitHub Desktop.
Easy Tunnel
#!/usr/local/bin/expect
log_user 0
spawn nc localhost 2000
stty raw -echo
interact -o -nobuffer
#!/usr/local/bin/expect
log_user 0
proc username {} { return "my_user_name" }
proc first_ssh {} { return "ssh server1" }
proc second_ssh {} { return "ssh server2" }
proc third_nc {} { return "nc db_host db_port" }
spawn "[first_ssh]"
expect {
"*[username]@host-*:~$ " {
send "[second_ssh]; exit\n"
expect {
"*Last login:*(*:* *app-*:*~*) " {
send "[third_nc]; exit\n"
interact
}
}
}
}
# terminal 1
nc -l 2000
# terminal 2
socat tcp-l:200 system:'./nc-test.exp'
# terminal 3
nc localhost 200
# when I write something and hit enter, it echoes back; this is what I see
# 1
# 1
# hello
# hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment