使用Python对投影仪的红外遥控器进行暴力攻击

2024-10-08 18:25:29 发布

您现在位置:Python中文网/ 问答频道 /正文

编辑:我想我几乎所有的东西都在工作。这只是我的第二个循环一直有索引失败。。。知道为什么我的通信循环失败了吗


我目前正在尝试获取HD180x optomoa投影仪的红外代码。这正变成一个非常困难的问题

我只需要打开电源,别的什么都不需要

我没有一个红外传感器直接捕捉代码,并且把它作为一个挑战,在没有红外传感器的情况下尝试去做

到目前为止,这是不可能的。我已经尝试了几种不同的方法,使用树莓Pi直接从远程获取IR代码,但没有成功

我的下一个想法是使用红外爆炸机,然后循环所有可能的红外通电代码

LIRC是唯一一款Pi-IR软件,它有很多遥控器的列表:http://lirc.sourceforge.net/remotes/

我想尝试做的是制作一个python脚本,从列表中获取所有文件,然后尝试所有文件。我们的目标就是打开投影仪,这样我就可以让它一直运行下去,如果它打开了,我就可以找出是哪个打开了

因此,我的伪代码如下所示:

  1. 下载整个远程列表
  2. 为整个远程列表编制索引。=rListinex[] 2a。停止LIRCD服务
  3. 用RLISTINDEX[]替换/etc/lirc/lircd.conf(一次移动一个文件) 3a。启动LIRCD服务(这样它就可以
  4. 从远程代码文件获取“名称”字段。=RNAME
  5. 获取远程代码文件中所有可能代码的列表=IRCODE_数组
  6. 运行irsend\u ONCE RNAME IRCODE\u数组[](在代码数组中循环)
  7. 返回到步骤3

我不确定如何从配置文件中获取“名称”字段和“代码”字段

另外,不知道如何通过python发送终端命令

有什么想法吗

我能够得到开始发送的代码,现在我只需要找出如何从conf文件中获取“IR代码”

我非常接近……我只需要能够执行“irsend list”“>;>;/home/pi/list.ist”,这样我就可以找到当前活动的远程设备的名称……我似乎不知道如何正确运行该命令。我想引号把它弄乱了


import os
import shutil
import subprocess
import time
# Using readline() 
count = 0
#os.remove("list.list")
os.system("touch /home/pi/com.list")
os.system("touch /home/pi/list.list")
os.system("systemctl start lircd")
for filename in os.listdir('confs'):
    currconf = "/home/pi/confs/" + filename
    print "**********start*******"
    print "1. ", filename
    #print "2. ", currconf
    #os.system("systemctl stop lircd")
    #subprocess.call('systemctl stop lircd', shell=True)
    shutil.move(currconf, "/etc/lirc/lircd.conf")


    subprocess.call('systemctl reset-failed lircd', shell=True)
    subprocess.call('systemctl restart lircd', shell=True)
    time.sleep(1)
    subprocess.call('systemctl status lircd | tail -3', shell=True)
   # os.system("systemctl start lircd")
   # irlist  = ""
    #print "3. ", irlist
    os.remove("/home/pi/list.list")
    os.remove("/home/pi/com.list")
    os.system('irsend list \"\" \"\" >> /home/pi/list.list')



    qbfile = open("/home/pi/list.list", "r")

    for aline in qbfile:
        values = aline.split()  
        print(values[0])

        rname = values[0].strip('\n')
        print "2. rname", rname
        comlist = 'irsend list ' + rname + ' \"\" >> /home/pi/com.list'
        print "3. comlist", comlist
        os.system(comlist)
        comfile = open("/home/pi/com.list", "r")
        for coms in comfile:
            comvalues = coms.split()  
            comand = comvalues[1]#.strip('\n')
            cmd =  "irsend SEND_ONCE " + rname + " " + comand
            print "4. cmd ", cmd
            time.sleep(.001)
            os.system(cmd)
    print "**********end*******"

Tags: 文件代码home列表远程ospisystem
1条回答
网友
1楼 · 发布于 2024-10-08 18:25:29

我把一切都搞定了。。这是密码

import os
import shutil
import subprocess
import time

#removes files to start fresh
os.system("touch /home/pi/com.list")
os.system("touch /home/pi/list.list")
os.system("systemctl start lircd")

#gets a sorted list of all the configuration files from LIRC remote storage
for filename in sorted(os.listdir('/home/pi/confs')):
    #gets the first file
    currconf = "/home/pi/confs/" + filename
    print "**********start*******"
    print "1. ", filename

 #moves the first config file to lircd.conf so restart can make it show up
    shutil.move(currconf, "/etc/lirc/lircd.conf")

#restarts lircd (the reset-failed is to make sure there are no time outs
    subprocess.call('systemctl reset-failed lircd', shell=True)
    subprocess.call('systemctl restart lircd', shell=True)
    time.sleep(1)
#shows the status of lircd
    subprocess.call('systemctl status lircd | tail -3', shell=True)

#removes files again to make sure it is fresh
    os.remove("/home/pi/list.list")
    os.remove("/home/pi/com.list")
# sends an iresend to get list of all remotes in the remote configuration file that was used and pits it in list.list to be used for configuration later
    os.system('irsend list \"\" \"\" >> /home/pi/list.list')


#opens list.list
    qbfile = open("/home/pi/list.list", "r")
#for all remotes in list.list
    for aline in qbfile:
#this gets the remote names        
        values = aline.split()  
        if values:
            print(values[0])
#removes end of file from remote names
            rname = values[0].strip('\n')
            print "2. rname", rname
#creates command that is going to list all commands of given remote names
            comlist = 'irsend list ' + rname + ' \"\" >> /home/pi/com.list'
            print "3. comlist", comlist
#runs command            
            os.system(comlist)
#opens command list file            
            comfile = open("/home/pi/com.list", "r")
            for coms in comfile:
#gets command name, and not command hex                
                comvalues = coms.split()  

                #makes sure if there is a null value it does not hang the loop
                if comvalues:
                    comand = comvalues[1]#.strip('\n')
                    print "4. cmd ", comand
                    time.sleep(.1)

                    command2 = 'irsend SEND_ONCE ' + rname + " " + comand
                    print "5. command2", command2
                    ppp = subprocess.Popen(command2, universal_newlines=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                    text = ppp.stdout.read()
                    retcode = ppp.wait()
                    print text


    print "**********end*******"

相关问题 更多 >

    热门问题