Home > Net >  How to grab specific details of device from result file using Python
How to grab specific details of device from result file using Python

Time:02-11

I have more than 100 Apple Devices in my office. I want the details of particular device I want

I used PyAtv a python module to scan the devices which are on my network.

So I created a script which gives me the result like this when called.

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

But I want to get the results of specific device

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

I tried a lot but the challenge I face is Multiple Services and Identifiers in the results

Any help is appreciated! Thanks!

CodePudding user response:

I assume you are using the scan function.

The scan function returns a List[interface.BaseConfig].

The BaseConfig contains the property name.

So, you can try:

name = '2424'

devices = scan(...)

for device in device:
    if device.name == name:
        my_device = device

CodePudding user response:

You either pass one or more identifiers (preferably all of them) to scan. Alternatively you can pass the IP address via hosts (does not work if the device is on another network though). It's described in the documentation:

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

  • Related