0

Apologies if its duplicate query, I am not able to find the answer for my question posting here.

I have developed a webpage in Djangos hosted in development server. Webpage is accessible for anyone outside the development box. requiremnet: when User access website, top right corener I want to display user computer name.(note: I am not asking users to register).

I wrote below code which is fetching user Name, but it alwyas shows admin display name from develoment box.

how to get user computer name where ever the webpage is opened in my LAN.

///view.py
import ctypes
def get_display_name():
    GetUserNameEx = ctypes.windll.secur32.GetUserNameExW
    NameDisplay = 3
    size = ctypes.pointer(ctypes.c_ulong(0))
    GetUserNameEx(NameDisplay, None, size)
    nameBuffer = ctypes.create_unicode_buffer(size.contents.value)
    GetUserNameEx(NameDisplay, nameBuffer, size)
    return(nameBuffer.value)

def home_page(request):
    context = {
        "username":request.user.username,
    }
    return render(request,"default.html", context)

//default.html
<div>{{username}}</div>

1 Answers1

0

I don't think that's possible. You're mentioning LAN, so I'm assuming it's just for local users? If so, you could create a dictionary for every computer on your network associating their IP with their computer name, or even user.

To go about getting their IP is much easier.

ip = request.META.get('HTTP_X_FORWARDED_FOR')

Though it's not reliable.

Some other answers on this topic:

Get domain/host

Getting IP

Stephen
  • 1,072
  • 1
  • 19
  • 33
  • Hi Stephen, Might be my requirement confused. we have developed website using Djangos. the website is open to any one in my organisation to access without any authentication. no AD and no LDAP connectivity. to capture the user who is accessing my website and to display user full name on webpages I need to crack a code. to wards that any solution will be highly appriciated. – Parabrahmachari Vadla Naga Nov 28 '18 at 07:42