Reputation: 1
so i have this website to manage the local network of my business i have 2 project inside it one is the callback server one is the main app that manage the local network. so i want to restrict to only people that can access the technician router can access the main app. i already make the view to get the client ip address but it return public ip but what i want is ip address that the user is connected that is in range "192.178.1.x ~ 192.178.50", can anyone help me?, if anyone have suggestion how can i used different method for this cases please just share it out. thanks :) here's code
views.py
def ip(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')
print(ip)
return HttpResponse(ip)
Upvotes: 0
Views: 232
Reputation: 2370
Your local IP can be found in python with the following code:
import socket
local_ip = socket.gethostbyname(socket.gethostname())
print(local_ip)
I don't know much about Django, but hopefully you can implement this snippet in your code.
Upvotes: 1