Hi Folks,
I'm a noob but I'm slowly getting addicted to python.
I've been hitting a wall for about 4 hours trying various things to no avail.
It looks to me like it should work and runs without error but....
I expect the blockcount counter to be high (but it's 1)
I expect the accountmatchcounter to be low but it's 131
(looks like they are wrongly placed from the results but I can't see the error in the logic.)
Hopefully one of you chaps will be able to have a giggle and set me straight in one minute.
(any more elegant examples of how to achieve the same results welcomed!)
At the bottom of the code is a sample of the (start of the) original input file I'm working with
it's the output from a wee utility called ntfsdump - the files are around 1.5mb in size
ideally I'd be using python to parse the directory structure reporting on the account anomalies but I'm a noob at python, can't install it on the servers and I'm too afraid to wrap an exe with py2exe and run this on a production server.
# Setup array of school accounts used in perms(only the ones we worry about if they're not there)
listofaccounts = ["spgstaff", "spgxstaff", "spmstaff"]
# setup log file
#log001=open("c:\log001.txt", "a") (for use at work)
log001=open("/home/scobie/Desktop/log001.txt", "a")
# open input file - first bit is tkinter gui and the last line deals with the file opening
import Tkinter
from tkFileDialog import askopenfilename
root = Tkinter.Tk()
root.withdraw() # hide the main GUI window for our example
nmapresultsfile = askopenfilename()
#################################################
### this codeblock from someone else --->
#################################################
#strip off the leading info - top 5 lines - save as nmaptrimmed for further operations below
tempFile = open(nmapresultsfile)
tempList = []
for lineNum, line in enumerate(tempFile):
if lineNum >= 0 and lineNum < 5:
continue # do next lineNum, line without append()
tempList.append(line)
tempFile.close()
#tempFile = open("c:\nmaptrimmed.txt", 'w') (for use at work)
tempFile = open("/home/scobie/Desktop/nmaptrimmed.txt", 'w')
tempFile.writelines(tempList)
tempFile.close()
#################################################
### <--- this codeblock from someone else
#################################################
###
# perform checks on each block in inputfile (blocks split with one empty line) incrementing blockcount as they are processed
# iterate over each line in block to check for the existence of any of the accounts in listofaccounts
# for each match add 1 to accountmatchcounter and if this is = 0 then add block number to logfile.
###
#inputfilename = open("c:\nmaptrimmed.txt", "r")
inputfilename = open("/home/scobie/Desktop/nmaptrimmed.txt", "r")
blockcount = 1 # set to increment when there's a blank line
accountmatchcounter = 1 # set to increment within each block iteration where there's a regex match
for line in inputfilename:
if line[0:1]=="c":
for item in listofaccounts:
if line.find(item)!=-1:
accountmatchcounter = accountmatchcounter + 1
else:
pass
elif accountmatchcounter == 0:
log001.writelines("possible problem - no account set in block " + repr(blockcount) + "\n")
blockcount = blockcount + 1
accountmatchcounter = 0
else:
pass
#################################################
#################################################
log001.close()
inputfilename.close()
#below is an example of the input file (it's just the start - it's around 1.5mb)
#23/09/2010 13:21 - Somarsoft DumpSec (formerly DumpAcl) - \\IT85112 (local)
#Path (exception dirs and files),Account ,Own ,Dir File ,Success Failure ,
#
#c:\shares\staffresources\
#
#c:\shares\staffresources\,SPGAS01\Administrators
#c:\shares\staffresources\,SCHOOLS\delpaisleygrammar
#c:\shares\staffresources\,SCHOOLS\Domain Admins
#c:\shares\staffresources\,SCHOOLS\edcorpusers
#c:\shares\staffresources\,SCHOOLS\spgstaff
#
#c:\shares\staffresources\art\,SPGAS01\Administrators
#c:\shares\staffresources\art\,SCHOOLS\spgart
#c:\shares\staffresources\art\,SCHOOLS\pgsartq
#
#c:\shares\staffresources\art\02Ali Boss.xlsx,SPGAS01\Administrators
#c:\shares\staffresources\art\02Ali Boss.xlsx,SCHOOLS\spgart
#c:\shares\staffresources\art\02Ali Boss.xlsx,SCHOOLS\spgpowerstaff
#c:\shares\staffresources\art\02Ali Boss.xlsx,SCHOOLS\spgxstaff
#c:\shares\staffresources\art\02Ali Boss.xlsx,SCHOOLS\spgjohnsa1