python红外发射
当你在linux下能成功用红外发射控制空调之后,如果你想用python实现以上功能
代码如下:
# -*- coding: utf-8 -*-
# !/usr/bin/python
import paramiko
import threading
import timedef ssh2(ip, username, passwd, cmd):try:ssh = paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect(ip, 22, username, passwd, timeout=5)for m in cmd:stdin, stdout, stderr = ssh.exec_command(m)# stdin.write("Y") #简单交互,输入 ‘Y’out = stdout.readlines()# 屏幕输出for o in out:printo,print'%s\tOK\n' % (ip)ssh.close()except:print'%s\tError\n' % (ip)if __name__ == '__main__':cmd = ['irsend SEND_ONCE aircon on'] # 你要执行的命令列表username = "pi" # 用户名passwd = "raspberry" # 密码threads = [] # 多线程print"Begin......"ip = '192.168.137.8'# a=threading.Thread(target=ssh2,args=(ip,username,passwd,cmd))# a.start()ssh2(ip, username, passwd, cmd)
python红外发射
当你在linux下能成功用红外发射控制空调之后,如果你想用python实现以上功能
代码如下:
# -*- coding: utf-8 -*-
# !/usr/bin/python
import paramiko
import threading
import timedef ssh2(ip, username, passwd, cmd):try:ssh = paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect(ip, 22, username, passwd, timeout=5)for m in cmd:stdin, stdout, stderr = ssh.exec_command(m)# stdin.write("Y") #简单交互,输入 ‘Y’out = stdout.readlines()# 屏幕输出for o in out:printo,print'%s\tOK\n' % (ip)ssh.close()except:print'%s\tError\n' % (ip)if __name__ == '__main__':cmd = ['irsend SEND_ONCE aircon on'] # 你要执行的命令列表username = "pi" # 用户名passwd = "raspberry" # 密码threads = [] # 多线程print"Begin......"ip = '192.168.137.8'# a=threading.Thread(target=ssh2,args=(ip,username,passwd,cmd))# a.start()ssh2(ip, username, passwd, cmd)
发布评论