import click
from pyicloud import PyiCloudService
api = PyiCloudService(‘xxxx@icloud.com’, ‘xxxx’)
if api.requires_2fa:
code = input('Enter the code you received of one of your approved devices: ')
result = api.validate_2fa_code(code)
if not result: raise RuntimeError(‘Failed to verify security code’)
if not api.is_trusted_session:
result = api.trust_session()
if not result: raise RuntimeError(‘Failed to request trust. You will likely be prompted for the code again in the coming weeks’)
elif api.requires_2sa:
devices = api.trusted_devices
for i, device in enumerate(devices):
print(
" %s: %s" % (i, device.get(‘deviceName’,
“SMS to %s” % device.get(‘phoneNumber’)))
)
device = click.prompt(‘Which device would you like to use?’, default=0)
device = devices[device]
if not api.send_verification_code(device): raise RuntimeError(‘Failed to send verification code’)
code = click.prompt(‘Please enter validation code’)
if not api.validate_verification_code(device, code): raise RuntimeError(‘Failed to verify verification code’)
成功认证之后,你就可以用这个接口干很多有意思的东西了,比如查询自己的账号在哪些设备上认证过了(这个其实可以间接地帮助你查询自己的账号是否被盗用过):
api.devices
效果如下:
查询对应的设备的物理位置(手机找不到的时候可以用?):
api.iphone.location() # 如果你只有一台关联该账号的苹果设备的话
api.devices[0].location() # []用来索引对应的设备
效果如下:
可以发现你手机的位置信息,例如经纬度,确定经纬度时是使用的WIfi还是蜂窝网络等等信息都是可以返回的。该API其实还可以实现很多有趣的功能(比如获得你的通讯录信息,备份你的iCloud里的文件等等),这个我们后面有时间可以继续介绍,这里为了不跑题,我们直接开始表演让手机自动发出声音吧,其实很简单,你只需要这样调用接口即可进行整蛊:
api.devices[1].play_sound() # 设备一定要选对,别回头吓到自己
过几秒钟之后,你的手机就会播放铃声并显示默认通知了(“查找我的 iPhone 警报”),并且将向您发送一封确认电子邮件。手机上的效果类似这样:
接下来,你只需要写个定时程序,指定每天晚上12点-凌晨3点每隔一段时间就让手机响一次就可以实现午夜凶铃的效果啦:
while True:
now_time = datetime.datetime.now()
hour = str(now_time).split(’ ‘)[1].split(’😂[0]
if hour in [‘00’, ‘01’, ‘02’]:
api.devices[1].play_sound()
time.sleep(random.randint(500, 800))
整理一下,完整源代码如下:
import time
import click
import random
import datetime
from pyicloud import PyiCloudService
api = PyiCloudService(‘xxx’, ‘xxx’)
if api.requires_2fa:
code = input('Enter the code you received of one of your approved devices: ')
result = api.validate_2fa_code(code)
if not result: raise RuntimeError(‘Failed to verify security code’)
if not api.is_trusted_session:
result = api.trust_session()
if not result: raise RuntimeError(‘Failed to request trust. You will likely be prompted for the code again in the coming weeks’)
elif api.requires_2sa:
devices = api.trusted_devices
最后
不知道你们用的什么环境,我一般都是用的Python3.6环境和pycharm解释器,没有软件,或者没有资料,没人解答问题,都可以免费领取(包括今天的代码),过几天我还会做个视频教程出来,有需要也可以领取~
给大家准备的学习资料包括但不限于:
Python 环境、pycharm编辑器/永久激活/翻译插件
python 零基础视频教程
Python 界面开发实战教程
Python 爬虫实战教程
Python 数据分析实战教程
python 游戏开发实战教程
Python 电子书100本
Python 学习路线规划
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!