Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help improving small vbs application

Posted on 2004-08-17
4
Medium Priority
?
868 Views
Last Modified: 2010-05-18
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>
===============
0
Comment
Question by:VAN
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 11824908
@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>
0
 
LVL 1

Author Comment

by:VAN
ID: 11825279
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.
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 2000 total points
ID: 11825351
This is.  It sends each line with it's own <pre> </pre> tags, so the browser should be able to render each line as it comes in.

===

<%@ LANGUAGE="VBSCRIPT" %>
<%
      Dim WshShell : Set WshShell = Server.CreateObject("WScript.Shell")
      
      ' Turn on Page Buffering for better results
      Response.Buffer = True
      
      Sub ShowOutput( strOutput )
            Response.Write "<pre>" & strOutput & "</pre>" & vbNewLine
            Response.Flush
      End Sub

      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
            Do While objProc.Status = 0
                  ' Write each line of output so far
                  Do While Not objOutput.AtEndOfStream
                        ShowOutput objOutput.ReadLine
                  Loop
            Loop

            ' Write rest of the results
            ShowOutput objOutput.ReadAll
      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>
0
 
LVL 1

Author Comment

by:VAN
ID: 11825483
That's it! Thanks, Dex!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question