Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Define the Telnet connection details
- TELNET_HOST="YOURCONSOLEIP"
- TELNET_PORT=23
- USERNAME="xbox"
- PASSWORD="xbox"
- CPU_INFO_COMMAND="sysinfo"
- # Create an expect script to handle the Telnet session
- expect <<EOF
- # Log the interaction to a file
- log_file telnet_log.txt
- # Connect to the Telnet server
- spawn telnet $TELNET_HOST $TELNET_PORT
- expect {
- timeout { send_user "Connection timed out\n"; exit 1 }
- eof { send_user "Connection failed\n"; exit 1 }
- "login:" { send_user "Connected to Telnet server\n" }
- }
- # Send the username
- send_user "Sending username...\n"
- send "$USERNAME\r"
- expect {
- timeout { send_user "Username input timed out\n"; exit 1 }
- "Password:" { send_user "Username accepted\n" }
- }
- # Send the password
- send_user "Sending password...\n"
- send "$PASSWORD\r"
- expect {
- timeout { send_user "Password input timed out\n"; exit 1 }
- -re "(#|>|\\$)" { send_user "Login successful\n" }
- "Login incorrect" { send_user "Login failed\n"; exit 1 }
- }
- # Send the command to retrieve CPU information
- send_user "Sending command to retrieve CPU information...\n"
- send "$CPU_INFO_COMMAND\r"
- expect {
- timeout { send_user "Command execution timed out\n"; exit 1 }
- -re "(#|>|\\$)" {
- send_user "CPU Information:\n"
- exp_send " \r"
- expect eof
- }
- }
- # Interact with the user for additional commands
- while {1} {
- send_user "\nEnter a command to send to the Telnet server (or 'exit' to quit): "
- expect_user -re "(.*)\n"
- set user_command $expect_out(1,string)
- if {$user_command == "exit"} {
- send_user "Exiting...\n"
- break
- }
- send "$user_command\r"
- expect {
- timeout { send_user "Command execution timed out\n"; exit 1 }
- -re "(#|>|\\$)" {
- send_user "Response:\n"
- exp_send " \r"
- expect eof
- }
- }
- }
- # Close the Telnet connection
- send "exit\r"
- expect eof
- EOF
- # Display the log file
- cat telnet_log.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement