Skip to content

Instantly share code, notes, and snippets.

@0x5e
Last active February 19, 2023 08:32
Show Gist options
  • Save 0x5e/0eab9304979a338c618b2b83b68387c7 to your computer and use it in GitHub Desktop.
Save 0x5e/0eab9304979a338c618b2b83b68387c7 to your computer and use it in GitHub Desktop.
Automate telnet login
#!/bin/bash
# This script is generated by chatgpt for telnet auto-login.
if [ $# -eq 0 ]; then
echo "Usage: $0 <host>"
exit 1
fi
host=$1
user=$(grep -A 2 "Host $host" ~/.ssh/config | grep User | awk '{print $2}')
password=$(grep -A 2 "Host $host" ~/.ssh/config | grep Password | sed 's/#//' | awk '{print $2}')
if [ -n "$user" ] && [ -n "$password" ]; then
expect -c "
spawn telnet $host
expect \"login:\"
send \"$user\r\"
expect \"Password:\"
send \"$password\r\"
interact
"
else
telnet $host
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment