/build/static/layout/Breadcrumb_cap_w.png

Run netstat -f in a batch file for a specific amount of time then quit and move on to the next command in the batch file?

I'm running a simple batch file that will return Windows system name, an sc query, and a specific netstat foreign address. The issue is that when the netstat cmd is run in the batch, it keeps running and running and running... It eventually quits, but long after it has returned the value I'm after in first ten seconds. How can one programmatically tell netstat to stop after say 30 seconds? I don't see any time related switches in the documentation... I see I can run it every 5 seconds... I just want it to stop after 30 seconds... so the batch file can move on to the next command...

2 Comments   [ + ] Show comments
  • What are you trying to determine? Maybe there's a different tool that you can use. - chucksteel 4 years ago
  • I'm using psexec to identify if a list of machines are communicating with the Crowdstrike cloud or not... so something like: netstat -f | findstr *list of Crowdstrike cloud ip* and it returns something like "ec2-54-183-140-32.us-west-1.compute.amazonaws.com:https ESTABLISHED" if all is ok and nothing if there is a problem. I can then identify the problem machines from the initial list. I am aslo checking for the csagent status, that is fast, so I have split it into two scripts. - kpm8 4 years ago

Answers (1)

Posted by: haway_the_lads 4 years ago
Senior White Belt
0

hi,

i would say use multiple scripts for that.

what i mean is get the parameters you need in a separate script and output it into a .log file or such.

then in the main script read the .log file and if the info inside it is satisfactory then close the script, move on to the next step.

like you said you need to read an output anyway so make it into a log file and that would solve the timeout you need.

in case you want to double check if the parameter in the netstat is still the one you want just copy the comand to run the script and read the output again after some steps


Comments:
  • Thanks haway. Good suggestion. - kpm8 4 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ