我的目标是在usb stick上查找文件,但首先我需要了解如何检测连接到计算机的usb stick。我有这段代码:
main.py
class tst(QtGui.QWidget):
def __init__(self):
super(tst, self).__init__()
ports = scanSerial()
print ports
port.py文件
def scanSerial():
available = []
for i in range(256):
try:
s = serial.Serial("/dev/ttyUSB" + str(i))
available.append(s.portstr)
s.close()
except serial.SerialException as e:
print e
return available
输出是:
[Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'
[Errno 2] could not open port /dev/ttyUSB1: [Errno 2] No such file or directory: '/dev/ttyUSB1'
[Errno 2] could not open port /dev/ttyUSB2: [Errno 2] No such file or directory: '/dev/ttyUSB2'
[Errno 2] could not open port /dev/ttyUSB3: [Errno 2] No such file or directory: '/dev/ttyUSB3'
[Errno 2] could not open port /dev/ttyUSB4: [Errno 2] No such file or directory: '/dev/ttyUSB4'
[Errno 2] could not open port /dev/ttyUSB5: [Errno 2] No such file or directory: '/dev/ttyUSB5'
[Errno 2] could not open port /dev/ttyUSB6: [Errno 2] No such file or directory: '/dev/ttyUSB6'
[Errno 2] could not open port /dev/ttyUSB7: [Errno 2] No such file or directory: '/dev/ttyUSB7'
[Errno 2] could not open port /dev/ttyUSB8: [Errno 2] No such file or directory: '/dev/ttyUSB8'
[Errno 2] could not open port /dev/ttyUSB9: [Errno 2] No such file or directory: '/dev/ttyUSB9'
如果我使用ttyS *而不是ttyUSB,那就有:
Could not configure port: (5, 'Input/output error')
Could not configure port: (5, 'Input/output error')
Could not configure port: (5, 'Input/output error')
Could not configure port: (5, 'Input/output error')
所以问题是如何进入被攻击的USB?
问候,马吕斯
编辑:将尝试pyUSB。谢谢大家!
答案 0 :(得分:1)
使用re和子进程模块:
std
当打印import re
import subprocess
device_re = re.compile("Bus\s+(?P<bus>\d+)\s+Device\s+(?P<device>\d+).+ID\s(?P<id>\w+:\w+)\s(?P<tag>.+)$", re.I)
df = subprocess.check_output("lsusb")
devices = []
for i in df.split('\n'):
if i:
info = device_re.match(i)
if info:
dinfo = info.groupdict()
dinfo['device'] = '/dev/bus/usb/%s/%s' % (dinfo.pop('bus'), dinfo.pop('device'))
devices.append(dinfo)
print devices
时,它应显示计算机当前使用的USB设备。
答案 1 :(得分:1)
尝试使用pyserial list_ports工具http://pyserial.readthedocs.io/en/latest/tools.html#module-serial.tools.list_ports示例:
CGPoint convertedRopePosition = CGPointMake(ropePhysicsBody.node.parent.position.x + ropePhysicsBody.node.position.x, ropePhysicsBody.node.parent.position.y + ropePhysicsBody.node.position.y);
SKPhysicsJointPin *jointPin = [SKPhysicsJointPin jointWithBodyA:monkeyPhysicsBody bodyB:ropePhysicsBody anchor:convertedRopePosition];
答案 2 :(得分:0)
您可以使用 pyUSB ,请参阅http://www.stackoverflow.com/questions/2487033/usb-device-identification列出附加设备,https://github.com/walac/pyusb/blob/master/docs/tutorial查看pyUSB教程
使用pyUSB枚举设备的代码
import bus
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print "Device:", dev.filename
print "idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor)
print "idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct)
(从http://www.stackoverflow.com/questions/2487033/usb-device-identification复制)