Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#!/usr/bin/env python3 import serial import time # Configuration port = "/dev/ttyUSB0" baudrate = 115200 login_prompt = "ts7600-4a9f81 login:" password_prompt = "Password:" success_prompt = "root@ts7600-4a9f81:~#" commands = ["uname -a"] # Open the serial port ser = serial.Serial(port, baudrate, timeout=1) def send_command(command, prompt): ser.write(command.encode('utf-8') + b'\n') ser.flush() while True: response = ser.readline().decode('utf-8') print(response, end='') if prompt in response: break try: # Wait for the "login:" prompt send_command('', login_prompt) # Enter the username ser.write("root\n".encode('utf-8')) # Wait for the "Password:" prompt send_command('', password_prompt) # Enter the password ser.write("asd123\n".encode('utf-8')) # Check for successful login response = ser.readline().decode('utf-8') if success_prompt not in response: print("Login failed.") ser.close() else: print("Login successful.") # Execute commands for command in commands: send_command(command, success_prompt) # Close the serial port ser.close() except serial.SerialException as e: print("Error: ", e)
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)