All Forums >> [Scripting] >> ASP.NET >> Retrieving Client Computer Name Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Posts: 2
Score: 0
Joined: 3/18/2005
From: USA
Status: offline
I attempting to retrieve the user name and client machine name of the person logged on to a computer on our intranet in ASP.NET. This is just for logging purposes. I am able to retrieve the user name easily enough via "User.Identity.Name" or "System.Security.Principal.WindowsIdentity.GetCurrent().Name", however I cannot get the CLIENT machine name. I have searched high and low and everything I have tried returns the machine name of the server. Any suggestions? Much appreciated!
AntarcticAlicia, I did look for a solution, but I couldn't find one.[V] Should this be a security issue ? Possibly, you can try in the Command window the "net" and the "nbtstat" commands. You get the possible options with /? as parameter. Good luck.
I played a bit with the command window. If I input "net view", then a list with computer names active on my LAN results. With "net view > pcnames.txt" you get the same results in that specified file. A script could take care for this command and thereafter use these computer names to search for the associated user names in the next way.
' Returns the user name of the user currently logged on ' to a remote computer. To use this script, replace ' RemoteComputer with the name of the remote computer ' you want to check.
' Script Code
strComputer = "RemoteComputer" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputer = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer in colComputer Wscript.Echo objComputer.UserName Next
' Source : The System Administration Scripting Guide, ' part of the Windows .NET Server Resource Kit. ' For more information, contact scripter@microsoft.com.
I hope you can use this idea.
< Message edited by didorno -- 7/20/2005 7:54:20 AM >
Posts: 2
Score: 0
Joined: 3/18/2005
From: USA
Status: offline
I HAVE A SOLUTION! Thank you so much for the suggestions. I have not tried them yet but I plan to do so to see if they will work for me. For now I wanted let you know that I found something else that finally worked for me:
Dim host As System.Net.IPHostEntry host = System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST")) strComputerName = host.HostName
I suppose I was trying to make it too difficult. Thanks for everything! ~Alicia