No announcement yet.

Get and IP Address from a Username

  • Filter
  • Time
  • Show
Clear All
new posts

  • Get and IP Address from a Username

    Hi all,

    Apolgies if this has already been asked...

    Is there anyway, using a person's AD username, get the IP address they have been assigned and/or workstation name of the computer they are on...



  • #2
    Re: Get and IP Address from a Username

    You typically have to get this from the computer side, rather that from the user. You can select your computers in Hyena's right window, then right-click and choose View Logged on Users. When that is finished you can use the Copy to Clipboard option and paste into Excel. Then refer to that spreadsheet whenever you need to find a user.


    • #3
      Re: Get and IP Address from a Username

      Hi, thanks for the reply.

      I do know about the option to see who is on a specific computer - the reason for my question is I am in a business where user's logon to different computers, and we use VNC to remote control them for troubleshooting, a lot of the time the user does not know their computer name and/or ip address.




      • #4
        Re: Get and IP Address from a Username

        Actualy I have a tool that can do what your asking. It is not 100% solid as net send's can fail for many reasons. First thing you could ask the user is to type %computername% in the Run line and ask them what the popup says. It should say something like "Windows can not find (users machine name). This will give you the name of their computer without having to walk a user through allot of right clicks and such.

        Please note that I used this tool from a share point on the net work. My command was called "Find Users Computer" The command was <span style="font-weight: bold">\\servername\Scripts\HyenaTools\Scripts\wher eisuser.bat %E%</span>

        Batch file:
        <span style="font-style: italic">@ECHO OFF
        ECHO Trying to find the computer that the user is logged into...

        NET SEND %1 "HelpDesk is looking for your computer -- Just Click OK"
        NBTSTAT -c | find /i "%1" > usr.txt
        FOR /f "tokens=4 delims= " %%i in (usr.txt) do set machineip=%%i
        PING -a -n 1 %machineip% > ip.txt
        TYPE ip.txt | find /i "Pinging" > ip1.txt
        FOR /f "tokens=2 delims= " %%i in (ip1.txt) do set machinename=%%i

        ECHO Username = %1
        ECHO IP Address = %machineip%
        ECHO Computer = %machinename%


        <span style="font-weight: bold">I have a couple of other find user files that also work. I will past the code for each file in italics.</span>

        <span style="font-weight: bold">finduser.js</span>
        <span style="font-style: italic">// Tommy Strِmgren, 2005-06-21 (tommy.stromgren (at)

        var oShell = new ActiveXObject("WScript.Shell");
        var oArgs = WScript.Arguments;
        var User = oArgs(0).toUpperCase().replace(/\/d/g, "");
        // Avoids accidental usage of the switch /d
        //(/d = send to entire domain)

        oShell.Exec("net send "+ oArgs(0) + " """);

        WScript.Sleep(500); // It takes some time before the NetBIOS cache displays the name
        var Cache = oShell.Exec("nbtstat -c").StdOut.ReadAll().replace(/\r/g,"");

        var UserLine = Cache.slice( Cache.indexOf( User ) );
        var UserLine = UserLine.slice( 0 , UserLine.indexOf("\n") );

        var UserIP = UserLine.slice(37 , 52).replace(/\s/g,"");

        var RemoteCache = oShell.Exec( "nbtstat -a " + UserIP ).StdOut.ReadAll().replace(/\r/g,"");

        "Empty "net send" message sent to: " + User +"\r\n" +
        "Local NetBIOS cache entry:\r\n"+UserLine +"\r\n\r\n" +
        "Registered NetBIOS Names on "+ UserIP +":"+ RemoteCache

        <span style="font-weight: bold">finduser.vbs</span>
        <span style="font-style: italic">'************* Begin Script Here *********
        '================================================= =========================
        ' VBScript Source File -- Created with SAPIEN Technologies PrimalSCRIPT(TM)
        ' NAME: FindUser.vbs
        ' AUTHOR: Joel Thoreson , USAALS / AEPCO
        ' DATE : 5/6/2003
        ' COMMENT: Finds a user on the domain.
        '================================================= =========================

        Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
        Dim WshNetwork : Set WshNetwork = WScript.CreateObject("WScript.Network")
        Dim objArgs : Set objArgs = WScript.Arguments ' create object with collection
        Dim fso : Set fso = WScript.CreateObject("Scripting.FilesystemObject")
        Const ForReading=1, ForWriting=2

        If objArgs.Count >= 1 Then
        strUserName = objArgs(0) 'assign the passed user name to a variable
        Else 'quit the script, no variable given, or too many variables passed
        strUserName = InputBox("Enter the loggon of the individual you wish to query",,WshNetwork.UserName)
        If strUserName = "" Then WScript.Quit
        End If

        If IsNull(strUserName) OR strUserName = "" Then WScript.Quit

        OutputFilePath = "c:\ip1.txt"

        ' Flush the cache
        WshShell.Run "cmd /c nbtstat.exe -R", 2, False
        WScript.Sleep 1000
        ' Send a message to the user
        WshShell.Run "cmd /c net send " & strUserName & " User locator message.", 2, True
        WScript.Sleep 1000
        ' check the local machines cache, looking for UNIQUE
        WshShell.Run "cmd /c nbtstat.exe -c | find ""UNIQUE"" > " & OutputFilePath, 2, True
        WScript.Sleep 1000

        On Error Resume Next

        Dim objFile : Set objFile = fso.OpenTextFile(OutputFilePath, ForReading)
        Dim strIPAddress : strIPAddress = Trim(Mid(objFile.ReadLine,42,15)) 'read the line

        ' Nobody home
        If Err.Number <> 0 Then
        WshShell.Popup "User '" & UCASE(strUserName) & "' is most likely not logged on anywhere.", 8, "User not found"
        End If

        WshShell.Run ("cmd /c nbtstat.exe -A " & strIPAddress & " > " & OutputFilePath)
        WScript.Sleep 1000

        Set objFile = fso.OpenTextFile(OutputFilePath, ForReading)

        Do While objFile.AtEndOfStream <> True
        aline=Trim(objFile.Readline) 'read a line
        SearchString = "<20>" '20 says file sharing is installed and enabled. See Below!!
        MyPos = Instr(1, aline, SearchString, 1) ' A textual comparison starting at
        If MyPos <> 0 Then
        strComputerName = Trim(Left(aline, (MyPos-1)))
        MsgBox "Machine Name: " & strComputerName
        End If

        Set objFile = Nothing

        ' when running nbtstat, these are the codes
        '00 Base computer name and Workgroups
        '01 Master Browser
        '03 Message Alert service (name of logged in user)
        '20 Resource Sharing `server service` name
        '1B Domain master-browser name
        '1C Domain controller name
        '1E Domain/workgroup master browser election announcement
        '**************** End Script Here *********

        [This message has been edited by Trammel (edited 09-13-2006).]