Skip to content

Commit

Permalink
Merge pull request #954 from doronz88/bugfix/movdev2-all-ip
Browse files Browse the repository at this point in the history
bonjour: browse all ip versions for mobdev2
  • Loading branch information
doronz88 authored Apr 22, 2024
2 parents a9a9860 + c5b1164 commit ac144d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions pymobiledevice3/bonjour.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def browse_ipv6(service_names: List[str], timeout: float = DEFAULT_BONJOUR
return await browse(service_names, OSUTILS.get_ipv6_ips(), timeout=timeout)


async def browse_ipv4(service_names: List[str], timeout: float = DEFAULT_BONJOUR_TIMEOUT) -> List[BonjourAnswer]:
def get_ipv4_addresses() -> List[str]:
ips = []
for adapter in get_adapters():
for ip in adapter.ips:
Expand All @@ -105,15 +105,19 @@ async def browse_ipv4(service_names: List[str], timeout: float = DEFAULT_BONJOUR
if not ip.is_IPv4:
continue
ips.append(ip.ip)
return await browse(service_names, ips, timeout=timeout)
return ips


async def browse_ipv4(service_names: List[str], timeout: float = DEFAULT_BONJOUR_TIMEOUT) -> List[BonjourAnswer]:
return await browse(service_names, get_ipv4_addresses(), timeout=timeout)


async def browse_remoted(timeout: float = DEFAULT_BONJOUR_TIMEOUT) -> List[BonjourAnswer]:
return await browse_ipv6(REMOTED_SERVICE_NAMES, timeout=timeout)


async def browse_mobdev2(timeout: float = DEFAULT_BONJOUR_TIMEOUT) -> List[BonjourAnswer]:
return await browse_ipv4(MOBDEV2_SERVICE_NAMES, timeout=timeout)
return await browse(MOBDEV2_SERVICE_NAMES, get_ipv4_addresses() + OSUTILS.get_ipv6_ips(), timeout=timeout)


async def browse_remotepairing(timeout: float = DEFAULT_BONJOUR_TIMEOUT) -> List[BonjourAnswer]:
Expand Down
6 changes: 4 additions & 2 deletions pymobiledevice3/cli/bonjour.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ async def cli_mobdev2_task(timeout: float, pair_records: str) -> None:
for record in Path(pair_records).glob('*.plist'):
records.append(plistlib.loads(record.read_bytes()))
output = []
for answer in await browse_mobdev2():
for answer in await browse_mobdev2(timeout=timeout):
for ip in answer.ips:
try:
lockdown = create_using_tcp(hostname=ip, autopair=False)
for pair_record in records:
lockdown = create_using_tcp(hostname=ip, autopair=False, pair_record=pair_record)
if lockdown.paired:
break
output.append(lockdown.short_info)
short_info = lockdown.short_info
short_info['ip'] = ip
output.append(short_info)
except ConnectionRefusedError:
continue
print_json(output)
Expand Down

0 comments on commit ac144d1

Please sign in to comment.