如何获得(时基)验证码,如 Google Authenticator(来自 android 应用程序)
How can I get a (time base) verification code like Google Authenticator (from the android app)
我想在网站上使用 API,但此服务限制了一些 API 方法与 2FA。
我确实需要每隔 10 分钟以编程方式调用此受限方法。
我会使用 python 脚本来获取时基验证码,例如 Google Authenticator 给我们...
但是给出的解决方案 here 并没有为我的移动设备和 python 脚本提供相同的代码。
Here 是 "Google Authenticator" 项目的源代码,但它是 Java ... 我需要(更喜欢)python !
我的问题是:在哪里可以找到 python 脚本来生成完全相同的代码。
提前致谢
最后它使用 https://github.com/pyotp/pyotp/tree/master/src/pyotp 与 python3
一起工作
示例:
from pyotp.hotp import HOTP
import time
hotp=HOTP()
secret_KEY="12345678901234567890123456789012"
while 1:
time.sleep(0.5)
print(hotp.counter_from_time())
hotp.generate_code_from_time(secret_key=secret_KEY, code_length=6, period=30)
给出:
(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 9.0)
('079310', 21)
[...]
我想在网站上使用 API,但此服务限制了一些 API 方法与 2FA。 我确实需要每隔 10 分钟以编程方式调用此受限方法。
我会使用 python 脚本来获取时基验证码,例如 Google Authenticator 给我们... 但是给出的解决方案 here 并没有为我的移动设备和 python 脚本提供相同的代码。
Here 是 "Google Authenticator" 项目的源代码,但它是 Java ... 我需要(更喜欢)python !
我的问题是:在哪里可以找到 python 脚本来生成完全相同的代码。
提前致谢
最后它使用 https://github.com/pyotp/pyotp/tree/master/src/pyotp 与 python3
一起工作
示例:
from pyotp.hotp import HOTP
import time
hotp=HOTP()
secret_KEY="12345678901234567890123456789012"
while 1:
time.sleep(0.5)
print(hotp.counter_from_time())
hotp.generate_code_from_time(secret_key=secret_KEY, code_length=6, period=30)
给出:
(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 9.0)
('079310', 21)
[...]