Get all current VNC Connections to your Computer including the hostname:
C:\>FOR /f "tokens=3*delims= " %a IN ('netstat -n^|find "5900"') DO @FOR /f "tokens=1*delims=:" %d IN ('echo %a^|find /v "5900"') DO @for /f "tokens=3delims= " %e in ('tracert -h 1 %d ^| find "max"') do @echo VNC connection from %e (%d) [%b]
Get all current VNC Connections from your Computer including the hostname:
FOR /f "tokens=3*delims= " %a IN ('netstat -n^|find "5900"') DO @FOR /f "tokens=1*delims=:" %d IN ('echo %a^|find "5900"') DO @for /f "tokens=3delims= " %e in ('tracert -h 1 %d ^| find "max"') do @echo VNC connection to %e (%d) [%b]
And here is a batch file ShowVncConnections.bat
for that purpose:
@echo off
FOR /f %%a in ('hostname') DO set hostname=%%a
FOR /f "tokens=3*delims= " %%a IN ('netstat -n^|find "5900"') DO @FOR /f "tokens=1*delims=:" %%d IN ('echo %%a^|find "5900"') DO @for /f "tokens=3delims= " %%e in ('tracert -h 1 %%d ^| find "max"') do @echo VNC connection from %hostname% to %%e (%%d) [%%b]
FOR /f "tokens=3*delims= " %%a IN ('netstat -n^|find "5900"') DO @FOR /f "tokens=1*delims=:" %%d IN ('echo %%a^|find /v "5900"') DO @for /f "tokens=3delims= " %%e in ('tracert -h 1 %%d ^| find "max"') do @echo VNC connection from %%e (%%d) to %hostname% [%%b]
pause
Produced Output:
VNC connection from MyComputer to AIP00000298 (172.20.17.55) [ESTABLISHED]
VNC connection from MyComputer to BMABN0014.aip.dagherp.local (172.20.17.67) [WAITING]
VNC connection from BMABN3145 (172.20.18.5) to MyComputer [ESTABLISHED]