Jump to content

Sorting windows Command Line programs output


Recommended Posts

Hi all,

I'd just like to ask a silly question if I may... I've built a PHP / MySQL based database system that keeps track of all our PCs in my workplace (>600) and it works a treat but I try to keep the reporting to simple exes that run on any of  NT/2K/XP platforms as we have these types of machines. so simple things like "net share" piped to text files work great but I was wondering if theres any program out there that can sort the output from command like net share, netstat etc. into proper tables, or csv files etc.. I could have sworn I saw one last week but I've lost the link. Maybe it doesn't exist at all and I'm just going mad but if anyone has any idea please let me know.

At the minute I'm pulling in the output into PHP and exploding it via rn  and then with t to seperate the tabs  and doing a bit of manipulation but it would be nice if there were an app out there that sorted the output of these commands. Actually the one I thought I saw was a windows built in thing I think. Or maybe it was a powershell thingy, which is useless cos I need this to run on NT-XP as I said before.

Either way, any info at all is much appreciated.

Link to comment
Share on other sites

I was wondering if theres any program out there that can sort the output from command like net share, netstat etc. into proper tables, or csv files etc..

Short of coding your own parsing routine in perl or c, you may want to look into running cygwin and utilizing the amazing power of Unix programs like sed and grep...

Actually, you don't even need to install the full image of cygwin, just keep the cygwin.dll in the directory of the program you're using. Then you can create a Windows batch file that parses the output files into temp files and operates on those.

Link to comment
Share on other sites

check out DUMPSEC you also want to get UnxUtils and learn SED / AWK and EGREP etc ..

here is a audit script I made to find all local admins administrators on a windows domain

its a total hack job but it works...

if all you want to do is keep track of network hosts just use whatsup is free for basic I think and also check out zenoss and nagios for more advanced stuff  http://rmccurdy.com/stuff/www.twatech.org/ look for the nagios eps.


net view | gawk "{print $1}"| sed "s//audit.vbs /g"  > script.bat
net view | gawk "{print $1}"| sed "s//audit.vbs /g"  > script.bat
cax /ruh script.bat | find /v "Domain Admins" | find /v "AGS" | find /v "adadmin" | find /v "adguest" | find /v "Microsoft" | find /v "Copyright" | grep " " > report.txt

script.bat | find /v "Domain Admins" | find /v "adadmin" | find /v "Microsoft" | find /v "Copyright" | grep " " > report.txt

type report.txt | find /v "audit" > report.wri

start report.wri


On Error Resume Next

strComputer = WScript.Arguments.Item(0)

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")

For Each objUser In objGroup.Members
Wscript.Echo strComputer & " " & objUser.Name


Link to comment
Share on other sites

Thanks for all your help op + hex.. I'll give these things a go. I had heard of cygwin but I was worried about how well it would work on each platform ie. does it work ok on NT? one way or another I'm gonna check it out.

I have a fairly decent amount of info in the database already but I just thought it'd be nice to have a simple exe or whatever that could parse info from solid native utilities / commands like "net share". I'm also having trouble running some commands directly from php using system / exec  and I found out lately that any utils I write in freebasic or whatever should be in one of the directories defined by 'PATH' variable on the webserver, ie. c:windows or whatever and that seems to work fine but when I run the "psexec remotecomputer net share" or "psexec -s -i -d remotecomputer net share" commands through PHP it just stalls and gives me maximum execution time errors. I could easily write a nice parser in PHP but basic is teh crap and I haven't really learned any C yet as I'm self taught and too busy. so if anyone has a proper way to run psexec through PHP please let me know.

So it's because psexec wasn't working through PHP that I originally wrote this thread. I was going to try to write the data from each machine to a file share on our server and if I could parse the data and send it to my webserver with curl well then all the better. They are very round-about ways of sending the data but it seems to work so I'm happy enough. If I was good enough I could build one big reporting app in C and connect directly to the MySQL server but I'm just not that good.

for the minute I'm going to look into what I've heard from you guys but if anyone has anything else to add, please do.

Thanks again.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...