Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help improving small vbs application

Posted on 2004-08-17
4
Medium Priority
?
867 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

722 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