Advertisement
Sweetening

Untitled

May 28th, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Define the Telnet connection details
  4. TELNET_HOST="YOURCONSOLEIP"
  5. TELNET_PORT=23
  6. USERNAME="xbox"
  7. PASSWORD="xbox"
  8. CPU_INFO_COMMAND="sysinfo"
  9.  
  10. # Create an expect script to handle the Telnet session
  11. expect <<EOF
  12. # Log the interaction to a file
  13. log_file telnet_log.txt
  14.  
  15. # Connect to the Telnet server
  16. spawn telnet $TELNET_HOST $TELNET_PORT
  17. expect {
  18. timeout { send_user "Connection timed out\n"; exit 1 }
  19. eof { send_user "Connection failed\n"; exit 1 }
  20. "login:" { send_user "Connected to Telnet server\n" }
  21. }
  22.  
  23. # Send the username
  24. send_user "Sending username...\n"
  25. send "$USERNAME\r"
  26. expect {
  27. timeout { send_user "Username input timed out\n"; exit 1 }
  28. "Password:" { send_user "Username accepted\n" }
  29. }
  30.  
  31. # Send the password
  32. send_user "Sending password...\n"
  33. send "$PASSWORD\r"
  34. expect {
  35. timeout { send_user "Password input timed out\n"; exit 1 }
  36. -re "(#|>|\\$)" { send_user "Login successful\n" }
  37. "Login incorrect" { send_user "Login failed\n"; exit 1 }
  38. }
  39.  
  40. # Send the command to retrieve CPU information
  41. send_user "Sending command to retrieve CPU information...\n"
  42. send "$CPU_INFO_COMMAND\r"
  43. expect {
  44. timeout { send_user "Command execution timed out\n"; exit 1 }
  45. -re "(#|>|\\$)" {
  46. send_user "CPU Information:\n"
  47. exp_send " \r"
  48. expect eof
  49. }
  50. }
  51.  
  52. # Interact with the user for additional commands
  53. while {1} {
  54. send_user "\nEnter a command to send to the Telnet server (or 'exit' to quit): "
  55. expect_user -re "(.*)\n"
  56. set user_command $expect_out(1,string)
  57. if {$user_command == "exit"} {
  58. send_user "Exiting...\n"
  59. break
  60. }
  61. send "$user_command\r"
  62. expect {
  63. timeout { send_user "Command execution timed out\n"; exit 1 }
  64. -re "(#|>|\\$)" {
  65. send_user "Response:\n"
  66. exp_send " \r"
  67. expect eof
  68. }
  69. }
  70. }
  71.  
  72. # Close the Telnet connection
  73. send "exit\r"
  74. expect eof
  75. EOF
  76.  
  77. # Display the log file
  78. cat telnet_log.txt
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement