Here’s a Python script that can locate a lost iPhone
Here’s a Python script that can help locate a lost iPhone using Apple’s “Find My iPhone” service via iCloud. It utilizes the pyicloud
library, which allows access to iCloud features, including device tracking.
Steps:
- Install
pyicloud
:pip install pyicloud
- Run the script and provide your Apple ID credentials.
- The script fetches the last known location of your iPhone.
Python Script to Locate a Lost iPhone:
from pyicloud import PyiCloudService
import time
# Replace with your Apple ID credentials
APPLE_ID = "your_email@example.com"
PASSWORD = "your_password"
# Login to iCloud
print("Logging into iCloud...")
api = PyiCloudService(APPLE_ID, PASSWORD)
# Handle Two-Factor Authentication (2FA)
if api.requires_2fa:
code = input("Enter the 2FA code sent to your Apple device: ")
result = api.validate_2fa_code(code)
if not result:
print("Invalid 2FA code.")
exit()
api.trust_session()
# Fetch devices
print("Fetching devices...")
devices = api.devices
# Locate iPhone
for device in devices:
if "iPhone" in device["deviceDisplayName"]:
location = device.location()
if location:
print(f"iPhone Found: {device['name']}")
print(f"Latitude: {location['latitude']}")
print(f"Longitude: {location['longitude']}")
print(f"Battery: {device['batteryLevel'] * 100}%")
else:
print("Location not available.")
break
else:
print("No iPhone found in your iCloud account.")
Features:
- Logs into iCloud and fetches devices.
- Handles Two-Factor Authentication (2FA).
- Retrieves and displays the last known location of your iPhone.
⚠ Disclaimer: Apple may require additional verification, and pyicloud
is an unofficial library. For official tracking, use the Find My iPhone feature in iCloud (https://www.icloud.com/find
).