Link to home
Start Free TrialLog in
Avatar of eli2011
eli2011

asked on

Tracert Monitor

hello
can this script be modified so it searches only a specific part of a txt file?
example:
right now running the script, FileName.vbs c:\FileLocation.txt 50 100 will find all values between 50 and 100, but this does not really work when you are scanning a trace route.  i need it to scan the first 4 columns of the tracert output and find the specified range.  can anyone help?  

i'm open to doing this a different way on a windows system.  batch file or vbs

argsCount = Wscript.Arguments.Count
if argsCount<>3 then
wscript.echo "Error: Wrong number of arguments (expected 3)"
wscript.quit
end if

dim lbound,ubound,data,ch,int
Set objFSO = CreateObject("Scripting.FileSystemObject")

file = Wscript.Arguments(0)
lbound = cInt(Wscript.Arguments(1))
ubound = cInt(Wscript.Arguments(2))

set objFile = objFSO.OpenTextFile(file, 1)

data = objFile.ReadAll
objFile.Close
token=""

for i=1 to len(data)

      ch = Mid(data,i,1)
      if IsNumeric(ch) = true then
            token = token & ch
      else
            if token <> "" then
                  int=cInt(token)
                  if int>=lbound and int<=ubound then
                        ''token is within range, send the email...
                        wscript.echo lbound & ">" & token & "<" & ubound
                  end if
                  token=""
            end if      
      end if
next
Avatar of BillDL
BillDL
Flag of United Kingdom of Great Britain and Northern Ireland image

What parameters/switches are you using with the TRACERT command to create your text file of results?

tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name

-d   Do not resolve addresses to host names.
-h   Maximum number of hops to search for target.
-j    Loose source route along the host-list.
-w  Timeout for each reply in milliseconds.
target_name    Name or IP address of the target host.

It should be possible to execute the command in a batch file and parse the output, splitting up each line into values in each column, and check if the values are within range.  There are a lot of other experts here who are more proficient at this type of thing than I am, but I can have a go if no others come along with a solution shortly.
Avatar of eli2011
eli2011

ASKER

i'm not using any of the switches they didn't seem to help.

ok thanks,
What do you mean by: " i need it to scan the first 4 columns of the tracert output and find the specified range.  can anyone help? "

Could you please give an example a a tracert text file and the range you are talking about?

In the mean while, I'v done a batch file that does what you asked, that is: "will find all values between 50 and 100"

 
@ECHO OFF

SET Dest=yahoo.com
SET LineStart=2
SET /a LineStartWithHeader=%LineStart% + 3
SET LineEnd=3

ECHO METHOD 1
FOR /F "skip=%LineStartWithHeader% delims=" %%A IN ('Tracert -h %LineEnd% %Dest% ^| Findstr -v "complete"') DO ECHO %%A
ECHO.

ECHO METHOD 2
FOR /F "skip=3 tokens=1* delims= " %%A IN ('Tracert -h %LineEnd% %Dest%') DO IF %%A GEQ %LineStart% IF %%A LEQ %LineEnd% ECHO %%A %%B


PAUSE

Open in new window

Just change LineStart and LineEnd as needed and Dest as needed.
Avatar of eli2011

ASKER

here are some hops to yahoo.com.  when i output this to a .txt file i need the script to scan just first 4 columns within a set range....in this case 50-100  i don't want it to scan dns/ip section of the each line.

on your batch script, how do you modify the range, lets say i want to use 100-200?

   
C:\>tracert yahoo.com


Tracing route to yahoo.com [67.195.160.76]
over a maximum of 30 hops:

  6    69 ms    70 ms    68 ms  cr2.ormfl.ip.att.net [12.122.106.118]
  7    81 ms    79 ms    80 ms  cr81.fldfl.ip.att.net [12.122.1.46]
  8    65 ms    67 ms    66 ms  fldfl01jt.ip.att.net [12.122.81.25]
  9    82 ms    74 ms    82 ms  192.205.36.254
 10    81 ms    90 ms    83 ms  ae-32-52.ebr2.Miami1.Level3.net [4.69.138.126]
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET Dest=yahoo.com
SET LineStart=100
SET /a LineStartWithHeader=%LineStart% + 3
SET LineEnd=200

FOR /F "skip=%LineStartWithHeader% Tokens=1-7 delims= " %%A IN ('Tracert -h %LineEnd% %Dest% ^| Findstr -v "complete"') DO (
	SET Line=%%A,%%B %%C, %%D %%E,%%F %%G
	SET Line=!Line: =!
	ECHO !Line!
)
	
PAUSE
EXIT

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ReneGe
ReneGe
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eli2011

ASKER

it seems to list all the lines regardless if it falls between 100 - 200


C:\batch\testing route>SETLOCAL enabledelayedexpansion

C:\batch\testing route>SET Dest=yahoo.com

C:\batch\testing route>SET HeaderLineNumber=3

C:\batch\testing route>SET LineStart=100

C:\batch\testing route>SET LineEnd=200

C:\batch\testing route>FOR /F "skip=3 Tokens=1-7 delims= " %A IN ('Tracert -h 20
0 yahoo.com | Findstr -v "complete"') DO (IF %A GEQ 100 IF %A LEQ 200 (
SET Line=%A,%B %C, %D %E,%F %G
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 1 GEQ 100 IF 1 LEQ 200 (
SET Line=1,1 ms, 2 ms,1 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 2 GEQ 100 IF 2 LEQ 200 (
SET Line=2,* *, * Request,timed out.
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 3 GEQ 100 IF 3 LEQ 200 (
SET Line=3,12 ms, 6 ms,9 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 4 GEQ 100 IF 4 LEQ 200 (
SET Line=4,6 ms, 8 ms,7 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 5 GEQ 100 IF 5 LEQ 200 (
SET Line=5,54 ms, 55 ms,54 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 6 GEQ 100 IF 6 LEQ 200 (
SET Line=6,67 ms, 68 ms,66 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 7 GEQ 100 IF 7 LEQ 200 (
SET Line=7,81 ms, 80 ms,80 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 8 GEQ 100 IF 8 LEQ 200 (
SET Line=8,148 ms, 97 ms,70 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 9 GEQ 100 IF 9 LEQ 200 (
SET Line=9,91 ms, 85 ms,92 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 10 GEQ 100 IF 10 LEQ 200 (
SET Line=10,79 ms, 85 ms,80 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 11 GEQ 100 IF 11 LEQ 200 (
SET Line=11,95 ms, 95 ms,102 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 12 GEQ 100 IF 12 LEQ 200 (
SET Line=12,108 ms, 113 ms,113 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 13 GEQ 100 IF 13 LEQ 200 (
SET Line=13,107 ms, 114 ms,150 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 14 GEQ 100 IF 14 LEQ 200 (
SET Line=14,109 ms, 126 ms,116 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 15 GEQ 100 IF 15 LEQ 200 (
SET Line=15,117 ms, 178 ms,91 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 16 GEQ 100 IF 16 LEQ 200 (
SET Line=16,109 ms, 92 ms,102 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 17 GEQ 100 IF 17 LEQ 200 (
SET Line=17,104 ms, 114 ms,117 ms
 SET Line=!Line: =!
 ECHO !Line!
) )

C:\batch\testing route>(IF 18 GEQ 100 IF 18 LEQ 200 (
SET Line=18,109 ms, 115 ms,109 ms
 SET Line=!Line: =!
 ECHO !Line!
) )
Have you removed "@ECHO OFF"  then piped the output of the batch file to a text file?

If you want to output the result to a file, use the following.

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET Dest=yahoo.com
SET HeaderLineNumber=3
SET LineStart=100
SET LineEnd=200

FOR /F "skip=%HeaderLineNumber% Tokens=1-7 delims= " %%A IN ('Tracert -h %LineEnd% %Dest% ^| Findstr -v "complete"') DO (
	IF %%A GEQ %LineStart% IF %%A LEQ %LineEnd% (
		SET Line=%%A,%%B %%C, %%D %%E,%%F %%G
		SET Line=!Line: =!
		ECHO !Line!
		ECHO !Line!>>Output.txt
	)
)
	
PAUSE
EXIT

Open in new window

Avatar of eli2011

ASKER

ran it exactly as the above and it doesn't create the output.txt file

ran it again with echo on and got the below.  it still shows all values inside of outside of 100-200


C:\batch2>SETLOCAL enabledelayedexpansion

C:\batch2>SET Dest=yahoo.com

C:\batch2>SET HeaderLineNumber=3

C:\batch2>SET LineStart=100

C:\batch2>SET LineEnd=200

C:\batch2>FOR /F "skip=3 Tokens=1-7 delims= " %A IN ('Tracert -h 200 yahoo.com |
 Findstr -v "complete"') DO (IF %A GEQ 100 IF %A LEQ 200 (
SET Line=%A,%B %C, %D %E,%F %G
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 1 GEQ 100 IF 1 LEQ 200 (
SET Line=1,2 ms, 2 ms,2 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 2 GEQ 100 IF 2 LEQ 200 (
SET Line=2,7 ms, 7 ms,7 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 3 GEQ 100 IF 3 LEQ 200 (
SET Line=3,7 ms, 11 ms,7 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 4 GEQ 100 IF 4 LEQ 200 (
SET Line=4,10 ms, 11 ms,11 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 5 GEQ 100 IF 5 LEQ 200 (
SET Line=5,56 ms, 58 ms,58 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 6 GEQ 100 IF 6 LEQ 200 (
SET Line=6,69 ms, 70 ms,69 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 7 GEQ 100 IF 7 LEQ 200 (
SET Line=7,79 ms, 79 ms,79 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 8 GEQ 100 IF 8 LEQ 200 (
SET Line=8,67 ms, 65 ms,68 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 9 GEQ 100 IF 9 LEQ 200 (
SET Line=9,76 ms, 82 ms,76 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 10 GEQ 100 IF 10 LEQ 200 (
SET Line=10,73 ms, 80 ms,86 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 11 GEQ 100 IF 11 LEQ 200 (
SET Line=11,82 ms, 82 ms,77 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 12 GEQ 100 IF 12 LEQ 200 (
SET Line=12,96 ms, 89 ms,89 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 13 GEQ 100 IF 13 LEQ 200 (
SET Line=13,112 ms, 103 ms,110 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 14 GEQ 100 IF 14 LEQ 200 (
SET Line=14,100 ms, 94 ms,99 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 15 GEQ 100 IF 15 LEQ 200 (
SET Line=15,129 ms, 354 ms,125 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 16 GEQ 100 IF 16 LEQ 200 (
SET Line=16,137 ms, 89 ms,129 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 17 GEQ 100 IF 17 LEQ 200 (
SET Line=17,100 ms, 95 ms,100 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 18 GEQ 100 IF 18 LEQ 200 (
SET Line=18,102 ms, 94 ms,100 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 19 GEQ 100 IF 19 LEQ 200 (
SET Line=19,104 ms, 107 ms,113 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>(IF 20 GEQ 100 IF 20 LEQ 200 (
SET Line=20,108 ms, 114 ms,112 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>Output.txt
) )

C:\batch2>PAUSE
Press any key to continue . . .
Works well for me. I tried this on a Windows 7 and XP Pro PC.

What is your OS?
Run this script and tell me what you get.
 
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET Var=a,b

FOR %%A IN (%Var%) DO (
	SET Val=VALUE=%%A
	ECHO !Val!
)

PAUSE

Open in new window

Avatar of eli2011

ASKER

VALUE=a
VALUE=b
Press any key to continue...
Avatar of eli2011

ASKER

i'm using win7
So enabledelayedexpansion works

What if create is but somehow, in another folder?

Try this insted. This will force the output file to be in the batch file folder, and named with that batch file name with the TXT extension.

 
@ECHO OFF

SETLOCAL enabledelayedexpansion

SET Dest=yahoo.com
SET HeaderLineNumber=3
SET LineStart=100
SET LineEnd=200

FOR /F "skip=%HeaderLineNumber% Tokens=1-7 delims= " %%A IN ('Tracert -h %LineEnd% %Dest% ^| Findstr -v "complete"') DO (
	IF %%A GEQ %LineStart% IF %%A LEQ %LineEnd% (
		SET Line=%%A,%%B %%C, %%D %%E,%%F %%G
		SET Line=!Line: =!
		ECHO !Line!
		ECHO !Line!>>"%~dpn0.txt"
	)
)
	
PAUSE
EXIT

Open in new window

Avatar of eli2011

ASKER

i tried it from an xp machine with a new OS

got this same thing shows all ranges of numbers and doesn't create the output file.  though it shows like it takes the name of the bat file to try creating the .txt file


C:\>SETLOCAL enabledelayedexpansion
C:\>SET Dest=yahoo.com
C:\>SET HeaderLineNumber=3
C:\>SET LineStart=100
C:\>SET LineEnd=200
C:\>FOR /F "skip=3 Tokens=1-7 delims= " %A IN ('Tracert -h 200 yahoo.com | Finds
tr -v "complete"') DO (IF %A GEQ 100 IF %A LEQ 200 (
SET Line=%A,%B %C, %D %E,%F %G
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
 LEQ 200 (F
, ,  ,
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 1 GEQ 100 IF 1 LEQ 200 (
SET Line=1,9 ms, <1 ms,<1 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 2 GEQ 100 IF 2 LEQ 200 (
SET Line=2,9 ms, 9 ms,9 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 3 GEQ 100 IF 3 LEQ 200 (
SET Line=3,9 ms, 9 ms,12 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 4 GEQ 100 IF 4 LEQ 200 (
SET Line=4,11 ms, 12 ms,31 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 5 GEQ 100 IF 5 LEQ 200 (
SET Line=5,12 ms, 44 ms,15 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 6 GEQ 100 IF 6 LEQ 200 (
SET Line=6,24 ms, 12 ms,12 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 7 GEQ 100 IF 7 LEQ 200 (
SET Line=7,10 ms, 12 ms,12 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 8 GEQ 100 IF 8 LEQ 200 (
SET Line=8,46 ms, 43 ms,37 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 9 GEQ 100 IF 9 LEQ 200 (
SET Line=9,89 ms, 91 ms,114 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 10 GEQ 100 IF 10 LEQ 200 (
SET Line=10,87 ms, 102 ms,86 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 11 GEQ 100 IF 11 LEQ 200 (
SET Line=11,88 ms, 86 ms,79 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 12 GEQ 100 IF 12 LEQ 200 (
SET Line=12,87 ms, 85 ms,84 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 13 GEQ 100 IF 13 LEQ 200 (
SET Line=13,100 ms, 88 ms,101 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 14 GEQ 100 IF 14 LEQ 200 (
SET Line=14,96 ms, 89 ms,88 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>(IF 15 GEQ 100 IF 15 LEQ 200 (
SET Line=15,85 ms, 103 ms,90 ms
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
 LEQ 200 (F
, ,  ,
 SET Line=!Line: =!
 ECHO !Line!
 ECHO !Line! 1>>"C:\test1.txt"
) )
C:\>PAUSE
Press any key to continue . . .
"though it shows like it takes the name of the bat file to try creating the .txt file" = This is by design.

I'm puzzled about your issue here.

Let's see what other experts has to say about this.

Cheers,
Rene
Avatar of eli2011

ASKER

sorry for the trouble
thanks

i am going to try it on a w2k3 server, btw.
Let me know how it goes.
FYI: Just tried it on another XP and w2003 server. Worked well.
Avatar of eli2011

ASKER

ok it's definitely not working for me, tried from xp, win7 and 2k3 server.  i'm just copying the script and pasting it exactly as it.  i attached it just in case .  the file creation is secondary for me, but you are saying that for you it displays only lines within the range specified?  cuz i get all lines TRtest.txt
What is your batch file name?
Avatar of eli2011

ASKER

trtest.bat
For a command prompt, try running it with the following command line:
CMD /V:ON "C:\Batch File Path\trtest.bat"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Part 2 of above (Hit Submit before I was done - Sorry)

Since your start and end points are 100 and 200 - Testing the line number will always product no txt file as the maximum number of hops over a tracert should never be more than 30  (15 levels of network up and 15 down)   Anything past that means something is really screwed up (i.e.) you would have to be going through a private network that went through some 70 routers before it actually hit the internet)

@DTHConsulting:
-Testing other columns was not a requirment.
-100 <> 200 : I was to focused on the requirments. I did not analyse it's raisability/limmitations. You are right and actually, I performed my test with a range of 2<>3.

@eli2011:
Would you mind running this command line and share the it's result with us as a attached file?
tracert yahoo.ca >C:\Tracert.txt
Avatar of eli2011

ASKER

When i changed it to this it worked.  created the file too
IF %%B GEQ %LineStart% if %%B LEQ %LineEnd% (
Interesting. If the line number is in the first column, and the FOR command starts with %%A, I wonder how then the line number end's up in the variable %%B.
Glad I could help.
Avatar of eli2011

ASKER

Thanks guys