문제상황
*DDoS 공격의 의미
DDoS(Distributed Denial of Service)는 웹사이트 또는 네트워크 리소스 운영이 불가능하도록 악성 트래픽을 대량으로 보내는 공격
해결방법
적용과정
@app.before_request
def block_method():
if 'x-real-ip' in request.headers:
ip=request.headers['x-real-ip']
else:
ip=request.environ.get('REMOTE_ADDR')
print("Current IP Address:",ip,flush=True)
print("Current Process:",os.getpid(),flush=True)
splited_ip=ip.split('.')
ip_range=splited_ip[0]+'.'+splited_ip[1]
if ip not in app.config['GOOD_IP_LIST'] and ip_range not in app.config['GOOD_IP_RANGE']:
abort(403)
if 'x-real-ip' in request.headers:
ip=request.headers['x-real-ip']
else:
ip=request.environ.get('REMOTE_ADDR')
splited_ip=ip.split('.')
ip_range=splited_ip[0]+'.'+splited_ip[1]
if ip not in app.config['GOOD_IP_LIST'] and ip_range not in app.config['GOOD_IP_RANGE']:
abort(403)
결과