- 🐚作者简介:花神庙码农(专注于Linux、WLAN、TCP/IP、Python等技术方向)
- 🐳博客主页:花神庙码农 ,地址:https://blog.csdn.net/qxhgd
- 🌐系列专栏:善假于物
- 📰如觉得博主文章写的不错或对你有所帮助的话,还望大家三连支持一下呀!!! 👉关注✨、点赞👍、收藏📂、评论。
- 如需转载请参考转载须知!!
# 导入模块
import serial
# 需要发送的串口指令
cmd = 'ifconfig'
# 将字符串转换成字节
cmd=bytes.fromhex(cmd)
# 生成串口
serial_com = serial.Serial("com1", 115200, timeout=5)
# 发送串口指令
serial_com.write(cmd)
# 读取串口返回结果
serial_com.read(1024)
# 关闭串口
serial_com.close()
#$language = "VBScript"
#$interface = "1.0"
Sub main
crt.Screen.Synchronous = True
While 1
crt.Screen.Send "ifconfig" & VbCr
crt.Screen.WaitForString "#"
crt.Sleep 1000*3
Wend
End Sub
#$language = "VBScript"
#$interface = "1.0"
Sub main
Dim ReadCounter
crt.Screen.Send VbCr
crt.Screen.WaitForString "login: "
crt.Screen.Send "root" & VbCr
crt.Screen.WaitForString "Password: "
crt.Screen.Send "root" & VbCr
crt.Screen.WaitForString "#"
for ReadCounter = 1 to 3
crt.Screen.Send "cat /proc/net/snmp" & VbCr
crt.Screen.WaitForString "#"
crt.Sleep 100
next
transmit "reboot^M"
End Sub
例1、自动执行100次ifconfig命令
proc main
integer Num ; Integer variable to increment.
for Num = 1 upto 100 ; Init variable and define loop.
transmit "ifconfig"
waitfor "#"
endfor
endproc
例2、周期查看pci设备并重启设备
proc main
integer WaitCounter= 0
while (WaitCounter++) < 1000
transmit "root^M"
waitfor "Password:"
transmit "root^M"
waitfor "#"
transmit "ls /proc/bus/pci/devices ^M"
waitfor "#"
transmit "reboot^M"
pause 2400
endwhile
endproc
#!/usr/bin/expect -f
set timeout 30
spawn ssh -l my_username@192.168.1.1
expect "password:"
send "my_password\r"
interact



