Script Examples for Windows NT/XP: Difference between revisions

From Free Knowledge Base- The DUCK Project
Jump to navigation Jump to search
New page: == 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 ...
 
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== Script Example A ===
== Script Example A ==


  BEGIN
  BEGIN
 
  ::Do a netstat without included name resolution;
  ::Do a netstat without included name resolution;
 
  ::find connection on port 5631 (pcAnywhere).
  ::find connection on port 5631 (pcAnywhere).
 
  netstat -a -n|findstr "5631" >A.txt 2>nul
  netstat -a -n|findstr "5631" >A.txt 2>nul
 
  ::Parse the IP address out of the returned string.
  ::Parse the IP address out of the returned string.
 
  for /f "tokens=4 delims=: " %%a in (A.txt) do call :GETNAMES %%a goto :cleanup
  for /f "tokens=4 delims=: " %%a in (A.txt) do call :GETNAMES %%a goto :cleanup
 
 
 
  :GETNAMES
  :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 g
  ::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>"
oto :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
  :CLEANUP
 
  if exist A.txt del A.txt
  if exist A.txt del A.txt
 
  if exist B.txt del B.txt
  if exist B.txt del B.txt


Line 33: Line 30:
[[Category:Computer_Technology]]
[[Category:Computer_Technology]]
[[Category:Microsoft]]
[[Category:Microsoft]]
[[Category:Windows]]

Latest revision as of 12:02, 17 October 2008

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