Here's a KiXforms script that I use...
Code:
Break On
$nul=SetConsole("Hide")
$frmMain = CreateObject("Kixtart.Form")
$frmMain.Caption = "Locate"
$frmMain.Icon = "shell32.dll;52"
$frmMain.Size = 285,155
$txtUser = $frmMain.TextBox("",10,10,200,20)
$txtUser.OnChange = "$$btnFind.Enabled=1"
$txtIP = $frmMain.TextBox("",10,40,200,20)
;$txtIP.Enabled = 0
$txtHost = $frmMain.TextBox("",10,70,200,20)
;$txtHost.Enabled = 0
$btnFind = $frmMain.Button("Find",$txtUser.Right+10,$txtUser.Top,50,20)
$btnFind.Enabled = 0
$btnFind.OnClick = "fnFindUser($$txtUser.Value) If @@ERROR fnERROR() EndIf"
$btnIP = $frmMain.Button("Copy",$txtIP.Right+10,$txtIP.Top,50,20)
$btnIP.Enabled = 0
$btnIP.OnClick = "fnCopyIP()"
$btnHost = $frmMain.Button("Copy",$txtHost.Right+10,$txtHost.Top,50,20)
$btnHost.Enabled = 0
$btnHost.OnClick = "fnCopyHost()"
$prgStatus = $frmMain.ProgressBar()
$prgStatus.Left = 10
$prgStatus.Top = $txtHost.Bottom+10
$prgStatus.Width = $frmMain.ClientWidth - 20
$prgStatus.Height = 20
$prgStatus.BorderStyle = 5
$prgStatus.Style = 1
$prgStatus.Max=3
$frmMain.Center
$frmMain.Show
While $frmMain.Visible
$nul=Execute($frmMain.DoEvents)
Loop
Exit 1
Function fnCopyIP()
$txtIP.SelStart = 0
$txtIP.SelLength = Len($txtIP.Text)
$txtIP.SetFocus() $txtIP.Copy()
EndFunction
Function fnCopyHost()
$txtHost.SelStart = 0
$txtHost.SelLength = Len($txtHost.Text)
$txtHost.SetFocus() $txtHost.Copy()
EndFunction
Function fnERROR()
$nul=MessageBox("User not found","Error")
EndFunction
Function fnFindUser($sUser)
$txtIP.Text = ""
$txtHost.Text = ""
$btnIP.Enabled = 0
$btnHost.Enabled = 0
$prgStatus.Value=0
$nul=WshPipe('Net Send '+$sUser+' ""',1)
If @ERROR Exit @ERROR EndIf
$prgStatus.Value=$prgStatus.Value+1
$aCon=WshPipe('nbtstat -c',1)
If @ERROR Exit @ERROR EndIf
$prgStatus.Value=$prgStatus.Value+1
For Each $sCon in $aCon
If Instr($sCon,$sUser)
$aFnd=Split($sCon," ")
For Each $sFnd in $aFnd
If Instr($sFnd,".") $sIP=$sFnd EndIf
Next
EndIf
Next
$aHost=WshPipe('Ping -a -n 1 $sIP',1)
$prgStatus.Value=$prgStatus.Value+1
If @ERROR Exit @ERROR EndIf
For Each $sHost in $aHost
If Instr($sHost,$sIP) and Instr($sHost,"Pinging")
$sCom=Split($sHost," ")[1]
EndIf
Next
$txtIP.Text = $sIP
$txtHost.Text = $sCom
$btnIP.Enabled = 1
$btnHost.Enabled = 1
$prgStatus.Value=0
EndFunction
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If Not $NoEcho $Output Endif
$WshPipe=Split($Output,@CRLF)
Exit($oExec.ExitCode)
EndFunction