I know I can use request.META[‘REMOTE_ADDR’] to get the client’s IP in my django view function.
However, I have no idea how to get the client remote port number.
For example, you can see your own remote port number on the site below:
MY VIEW PY:
if request.user.is_authenticated:
gelenIleti = request.META.get('HTTP_X_FORWARDED_FOR')
if gelenIleti:
ip = gelenIleti.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
portNumarasi = request.META['SERVER_PORT']
logger.info(' ' + 'LOG KAYDI :' + ' ' + ' KULLANICI : ' + request.user.username + ' ' + ' IP : ' + ip + ' ' + ' SERVER PORT : ' + portNumarasi)
UPDATE: (SOLVED)
I solved the problem by this way;
sock = request._stream.stream.stream.raw._sock client
ip, port = sock.getpeername()