Script Examples for Windows NT/XP

From Free Knowledge Base- The DUCK Project
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Script Example A

BEGIN

::Do a netstat without included name resolution;

::find connection on port 5631 (pcAnywhere).

netstat -a -n|findstr "5631" >A.txt 2>nul

::Parse the IP address out of the returned string.

for /f "tokens=4 delims=: " %%a in (A.txt) do call :GETNAMES %%a goto :cleanup



:GETNAMES

::Do nbtstat to the remote IP address, and parse out the ::<20> name, which is the NetBIOS name of the PCA Client. if %1==0.0.0.0 goto :EOF nbtstat -A %1|findstr "<20>" >>B.txt ::Errorlevel 1 is returned if the above findstr was unsuccessful; ::tell user and quit. IF errorlevel 1 (echo No PCA connection exists) & goto :CLEANUP ::NetBIOS creates <03> entries for username and machinename; ::get them with nbtstat to the remote machine and print out. for /f "tokens=1" %%a in (B.txt) do nbtstat -a %%a|findstr "<03>"



:CLEANUP

if exist A.txt del A.txt

if exist B.txt del B.txt