Link to home
Start Free TrialLog in
Avatar of VAN
VAN

asked on

Need help improving small vbs application

I am using the following code to run ping and tracert commands from a browser. Thanks to   DexStar for the code. This works great, but it is pretty slow to respond, since it waits to complete the operation before painting the screen. Can this be modified to paint line-by-line results as they occur in order to speed up the process?

=================
<%@ LANGUAGE="VBSCRIPT" %>
<%
     Dim WshShell : Set WshShell = Server.CreateObject("WScript.Shell")
     
     ' Turn on Page Buffering for better results
     Response.Buffer = True

     Sub ExecCMD( strExec, strTitle )
          Dim proc, n

          ' Write the title, and send it to the browser
          Response.Write "<H1>" & strTitle & "</H1>"
          Response.Flush

          ' Execute the command and wait for it to finish
          Set proc = WshShell.Exec( strExec )
          Do While proc.Status = 0
               ' Anyone know a better way to wait?  WScript.Sleep doesn't work in ASP
               n = n + 1
          Loop

          ' Write the results, and send it to the browser
          Response.Write "<pre>" & proc.StdOut.ReadAll & "</pre>"
          Response.Flush
     End Sub
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Test Results</TITLE>
</HEAD>
<BODY>
<%
     Dim strIP : strIP = Request.QueryString("IP")
     
   If ( strIP & "" <> "" ) Then
          If ( InStr(strIP, " ") = 0 ) Then
               ExecCMD "cmd /c ping " & strIP, "Ping Results"
               ExecCMD "cmd /c tracert " & strIP, "Trace Route Results"
          Else
               Response.Write "Bad H4x0r, No Ping Flood!"
          End If
     Else
          Response.Write "No IP provided!"
     End If
%>
</BODY>
</HTML>
===============
Avatar of Dexstar
Dexstar

@Van:

Try the code that I posted below.  It should fix your issue with the delayed output.  I know it will for sure send the results to the browser as they happen, but I'm not sure if the browser will render them until it gets the </pre> tag.  If not, we might have to tweak it a little.  Let me know what you find out.

-D*

===

<%@ LANGUAGE="VBSCRIPT" %>
<%
      Dim WshShell : Set WshShell = Server.CreateObject("WScript.Shell")
      
      ' Turn on Page Buffering for better results
      Response.Buffer = True

      Sub ExecCMD( strExec, strTitle )
            Dim objProc, objOutput

            ' Write the title, and send it to the browser
            Response.Write "<H1>" & strTitle & "</H1>" & vbNewLine
            Response.Flush

            ' Execute the command and wait for it to finish
            Set objProc = WshShell.Exec( strExec )
            Set objOutput = objProc.StdOut
            Response.Write "<pre>"
            Do While objProc.Status = 0
                  ' Read each line of output so far
                  Do While Not objOutput.AtEndOfStream
                        Response.Write objOutput.ReadLine
                  Loop
                  ' Send it to the browser
                  Response.Flush
            Loop

            ' Write rest of the results
            Response.Write objOutput.ReadAll
            Response.Write "</pre>" & vbNewLine
            Response.Flush
      End Sub
%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Test Results</TITLE>
</HEAD>
<BODY>
<%
      Dim strIP : strIP = Request.QueryString("IP")
      
      If ( strIP & "" <> "" ) Then
            If ( InStr(strIP, " ") = 0 ) Then
                  ExecCMD "cmd /c ping " & strIP, "Ping Results"
                  ExecCMD "cmd /c tracert " & strIP, "Trace Route Results"
            Else
                  Response.Write "Bad H4x0r, No Ping Flood!"
            End If
      Else
            Response.Write "No IP provided!"
      End If
%>
</BODY>
</HTML>
Avatar of VAN

ASKER

Thanks for the reply, Dex, but this is giving the ame results. It waits until it has all data before printing it to the screen.
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

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 VAN

ASKER

That's it! Thanks, Dex!