妈妈,我的 GitHub 上不去了!
由于一些奇怪的原因,GitHub 疑似遭到了中间人攻击,对我们开发者来说,这个绝对是个噩耗,恨不得盯着 GitHub 页面疯狂刷新。但这种方法是不可取的。所为一个程序员,怎能用这种方法折磨自己呢?
截至写文章时,我通过下面的脚本监测到 GitHub 已在
2020-3-27 09:40:36
恢复,又在2020-3-27 09:48:05
继续被中间人攻击,然后2020-3-27 09:51:36
又好了。。。
0x00 思路
如果用 requests
代替人工对 GitHub 进行请求,返回的 HTTP 状态码是 200 的话,不就说明可以正常访问了吗?
反之,如果抛出了 requests.exceptions.SSLError
异常,就说明依然遭到中间人攻击。
0x01 代码
有了这些思路,我们来写代码:
import requests
import time
def log(text): # 简易的 log
print('[%s] %s' % (time.strftime("%H:%M:%S", time.localtime()), text))
def main(github_url, delay):
while True:
try:
github = requests.get(github_url)
if github.status_code == 200:
log('200')
else:
log( github.status_code)
except requests.exceptions.SSLError:
log('SSLError')
except Exception as e:
log(repr(e))
time.sleep(delay)
if __name__ == '__main__':
main('https://github.com/', 5)
0x02 命令行输出(部分)
[09:50:44] SSLError
[09:50:49] SSLError
[09:50:54] SSLError
[09:50:59] SSLError
[09:51:04] SSLError
[09:51:10] SSLError
[09:51:15] SSLError
[09:51:20] SSLError
[09:51:25] SSLError
[09:51:30] SSLError
[09:51:36] 200
[09:51:42] 200
[09:51:47] 200
[09:51:53] 200
0x03 结尾
这状态咋一直在变。。。
Comments | 2 条评论
Xiao_Jin,我来围观你的文章了,为你点赞!
@Xiaohao520