首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Python从结果文件中获取设备的特定细节

如何使用Python从结果文件中获取设备的特定细节
EN

Stack Overflow用户
提问于 2022-02-10 09:57:54
回答 2查看 79关注 0票数 0

我的办公室里有100多台苹果设备。我想知道我想要的设备的细节

我使用PyAtv一个python模块来扫描网络上的设备。

所以我创建了一个脚本,它在调用时给我这样的结果。

代码语言:javascript
复制
rexter@rexter-pc:~$ python3 scan.py

Scan Results
========================================
       Name: Himanshu Gupta’s Mac mini (intel)
   Model/SW: Macmini8,1, Unknown OS
    Address: 192.168.3.243
        MAC: F0:18:98:EF:D2:E6
 Deep Sleep: False
Identifiers:
 - F0:18:98:EF:D2:E6
 - F01898EFD2E6
Services:
 - Protocol: AirPlay, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: RAOP, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory

       Name: Home Cinema
   Model/SW: Apple TV 4K, tvOS 14.4 build 18K802
    Address: 192.168.3.19
        MAC: C8:D0:83:B0:70:C7
 Deep Sleep: False
Identifiers:
 - C8:D0:83:B0:70:C7
 - 257B0C06-0227-4E42-AEEA-3C2C42B3E829
 - C8D083B070C7
Services:
 - Protocol: AirPlay, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: Companion, Port: 49152, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: MRP, Port: 49153, Credentials: None, Requires Password: False, Password: None, Pairing: Optional
 - Protocol: RAOP, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory

       Name: Pluto - GROUND FLOOR
   Model/SW: ShairportSync, Unknown OS
    Address: 172.17.100.55
        MAC: None
 Deep Sleep: False
Identifiers:
 - E4BB83B4A641
Services:
 - Protocol: RAOP, Port: 8901, Credentials: None, Requires Password: False, Password: None, Pairing: NotNeeded

       Name: 2424
   Model/SW: Apple TV 4K, tvOS 15.0
    Address: 172.17.88.11
        MAC: DC:56:E7:59:79:46
 Deep Sleep: False
Identifiers:
 - DC:56:E7:59:79:46
 - DC56E7597946
Services:
 - Protocol: Companion, Port: 49152, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: AirPlay, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: RAOP, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory

但我想知道特定设备的结果

代码语言:javascript
复制
EXAMPLE >>> python3 scan.py 2424

       Name: 2424
   Model/SW: Apple TV 4K, tvOS 15.0
    Address: 172.17.88.11
        MAC: DC:56:E7:59:79:46
 Deep Sleep: False
Identifiers:
 - DC:56:E7:59:79:46
 - DC56E7597946
Services:
 - Protocol: Companion, Port: 49152, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: AirPlay, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory
 - Protocol: RAOP, Port: 7000, Credentials: None, Requires Password: False, Password: None, Pairing: Mandatory

我试了很多次,但我面临的挑战是多个ServicesIdentifiers

任何帮助都是非常感谢的!谢谢!

EN

回答 2

Stack Overflow用户

发布于 2022-02-10 10:20:39

我假设您使用的是scan函数。

scan函数返回一个List[interface.BaseConfig]

BaseConfig包含属性name

所以,你可以试试:

代码语言:javascript
复制
name = '2424'

devices = scan(...)

for device in device:
    if device.name == name:
        my_device = device
票数 0
EN

Stack Overflow用户

发布于 2022-02-10 20:53:10

您可以传递一个或多个标识符(最好是所有标识符)来扫描:

代码语言:javascript
复制
# Single identifier
confs = await pyatv.scan(loop, identifier="id")

# Multiple identifiers
confs = await pyatv.scan(loop, identifier={"id1", "id2", "id3"})

它与运行atvremote scan时看到的标识符相同。

或者,您可以通过主机传递IP地址(如果设备位于另一个网络上,则不工作)。

代码语言:javascript
复制
confs = await pyatv.scan(loop, hosts=["10.0.0.6"])

这里的文档也对此进行了描述:

https://pyatv.dev/development/scan_pair_and_connect/#scan

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71063017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档