Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Need help on redirecting output and search results in script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,54331
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need help on redirecting output and search results in script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Need help on redirecting output and search results in s... - 12/14/2007 5:50:06 AM   
  sdm44990

 

Posts: 8
Score: 0
Joined: 1/26/2007
Status: offline
I have a little script to run a portqry from and I was trying to figure out a way so that I can direct the output of this script into a temporary file and do a search for the port status, like Listening, Not Listening, or Filtered and have a wscript box that pops up with the results.  I guess the overall goal is to eventually put this into an HTA, but I'm kind of stuck with trying to figure out how to redirect the output and search the temp location of its output, any ideas or assistance would be greatly appreciated.  Here is the current snippet I'm using:

'set variables
Dim strSystem, strPort
'requesting user input
strSystem = InputBox("Enter Computer Name to Query for Ports" & vbcrlf & _
"Please enter the Computer name or IP Address", "Enter Computer Name")
strPort = InputBox("Enter Port to Query" & vbcrlf & _
"Please Enter Port to Query", "Enter Port")
Set objShell = CreateObject("WScript.Shell")
'setting command line interpreter and run portqry against server
objShell.Run "%COMSPEC% /k C: & cd C:\ & portqry -n " & strSystem & " -e " & strPort
 
 
Post #: 1
 
 RE: Need help on redirecting output and search results ... - 12/14/2007 6:30:50 AM   
  trsix

 

Posts: 21
Score: 0
Joined: 12/6/2006
From: Vancouver BC
Status: offline
This might be what you are looking for... or atleast point you in the right direction
This runs on the local system and displays each state in its own msgbox

Dim strTimeWait, strEstablished, strListening, strCloseWait, strOther
Dim objShell, objWshScriptExec, arrQueryOutput

Set objShell = CreateObject("WScript.Shell")
'netstat actually provides the full information regarding the systems ports
Set objWshScriptExec = objShell.exec ("netstat -a ")
'put the entire output of netstat -a into an object
SET objOutput = objWshScriptExec.Stdout
'here you can choose what ever you want, i went with if/then's but you could use case
While not objOutput.AtEndOfStream
   strLine = objOutput.ReadLine
   If Instr(strLine, "TIME_WAIT") <> 0 Then
       strTimeWait = strTimeWait & strLine & vbCrLf
   ElseIf Instr(strLine, "ESTABLISHED") <> 0 Then
       strEstablished = strEstablished & strLine & vbCrLf
   ElseIF Instr(strLine, "LISTENING") <> 0 Then
       strListening = strListening & strLine & vbCrLf
   ElseIF Instr(strLine, "CLOSE_WAIT") <> 0 Then
       strCloseWait = strCloseWait & strLine & vbCrLf
   Else
       strOther = strOther & strLine & vbCrLf
   End If
WEnd
'output the final to msgboxes
MsgBox("Time_Wait Connections" & vbCrLf & strTimeWait)
MsgBox("Established Connections" & vbCrLf & strEstablished)
MsgBox("Listening Connections" & vbCrLf & strListening)
MsgBox("Close_Wait Connections" & vbCrLf & strCloseWait)
MsgBox("Other Connections" & vbCrLf & strOther)

(in reply to sdm44990)
 
 
Post #: 2
 
 RE: Need help on redirecting output and search results ... - 12/14/2007 8:53:21 AM   
  sdm44990

 

Posts: 8
Score: 0
Joined: 1/26/2007
Status: offline
Looks promising, I'll try it, thanks alot!  I appreciate it!

(in reply to trsix)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need help on redirecting output and search results in script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts