initial commit done , pre peoduction
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import requests
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
def home(request):
|
||||
return render(request, 'home.html')
|
||||
|
||||
|
||||
def robots(request):
|
||||
return render(request, 'robots.txt')
|
||||
|
||||
|
||||
class Doxme(APIView):
|
||||
def get_client_ip(self, request):
|
||||
"""Get the user's IP from the request headers"""
|
||||
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
||||
if x_forwarded_for:
|
||||
ip = x_forwarded_for.split(',')[0] # First IP in the chain
|
||||
else:
|
||||
ip = request.META.get('REMOTE_ADDR')
|
||||
return ip
|
||||
|
||||
def get(self, request):
|
||||
client_ip = self.get_client_ip(request)
|
||||
|
||||
token = os.getenv('TOKEN')
|
||||
url = f'http://api.ipinfo.io/lite/{client_ip}?token={token}'
|
||||
ip_info = requests.get(url)
|
||||
|
||||
if ip_info.ok and not ip_info.json().get('bogon'):
|
||||
print(ip_info)
|
||||
return Response({'method': 'get', 'ip_info': ip_info.json()}, status=status.HTTP_200_OK)
|
||||
return Response({'message': 'error at ipinfo'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
Reference in New Issue
Block a user