Skip navigation

JSI Tip 0771. A quick way to determine the IPAddress where UserName is logged on from.


You can type:

NBTSTAT -c

and receive a display similar to:


Node IpAddress: \[0.0.0.0\] Scope Id: \[\]
            NetBIOS Remote Cache Name Table
    Name            Type            Host Address    Life \[sec\]
------------------------------------------------------------
GREYSTONE             UNIQUE      192.168.1.30        010
If the user is not listed, type:

net send jennifer hello
NBTSTAT -c


Node IpAddress: \[0.0.0.0\] Scope Id: \[\]
              NetBIOS Remote Cache Name Table
    Name            Type            Host Address    Life \[sec\]
------------------------------------------------------------
JENNIFER              UNIQUE      192.168.1.20        001
GREYSTONE             UNIQUE      192.168.1.30        013
If you need to do this in a batch job, call WhatIP UserName. It will return the whatip environment variable with the IP address, or a 0 if the user is not found.

Example:

call whatip Jennifer
if "%whatip%"

"0" goto notfound

WHATIP.BAT contains:

@echo off
set whatip=
if "%1"

"" goto syntax
set userv=%1
set userv=%userv:"=%
:again
nbtstat -c|find /i "%userv%" > %temp%\where.log
for /f "Tokens=1-7* Delims=. " %%i in (%temp%\where.log) do call :parse "%%i" "%%j" "%%k" "%%l" "%%m" "%%n" "%%o"
if "%whatip%"

"" goto donbt
if exist %temp%\where.log del /q %temp%\where.log
set userv=
goto end
:syntax
@echo Syntax: Where UserName
goto end
:parse
if /i not %1

"%userv%" goto donbt
if /i not %2

"" goto end
set whatip=%4%5%6%7
set whatip=%whatip:""=.%
set whatip=%whatip:"=%
goto end
:donbt
if "%whatip%"

"0" goto end
net send "%userv%" Ignore this interruption
set whatip=0
goto again
:end

You could try using NTNAME instead of NET SEND.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish