我正在获得一些有意尝试在我的IP上查找漏洞的机器人,而我所要做的就是手动阻止IP。
例如,以django发送到我的电子邮件中的错误开头
Invalid HTTP_HOST header: '68.183.112.215'. You may need to add '68.183.112.215' to ALLOWED_HOSTS.
Report at /.well-known/security.txt
Invalid HTTP_HOST header: '68.183.112.215'. You may need to add '68.183.112.215' to ALLOWED_HOSTS.
Request Method: GET
Request URL: https://68.183.112.215/.well-known/security.txt
我需要知道错误类型为无效的HTTP_HOST,然后列出IP地址
HTTP_X_REAL_IP = '198.20.70.114'
解析此字段以获取IP
我认为这应该有效
def handler500(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
#check if Invalid HTTP_HOST header
#if so run script to add ip to blocked ip's
#if possible let the normal 500 error to be raised
....
#otherwise raise custom error
如果我可以找出错误类型,那么可以尝试一下。厌倦了手动执行此操作。