Re: Basic Python V3 Search Tool using RE module

2015-03-26 Thread Gregg Dotoli
On Wednesday, March 25, 2015 at 3:43:38 PM UTC-4, Gregg Dotoli wrote:
> This basic script will help to find 
> evidence of CryptoWall on a slave drive. Although it is
> just a string, more complex regex patterns can be 
> replaced with the string. It is incredible how fast Python is and
> how easy it has helped in quickly assessing a pool of slave drives.
> I'm improving it as we speak.
> 
> 
> Thanks for your help and patience. I'm new with Python.
> 
> 
> import os
> import re
> # From the Root
> topdir = "."
> 
> # Regex Pattern
> pattern="DECRYPT_I"
> regexp=re.compile(pattern)
> for dirpath,dirnames, files in os.walk(topdir):
> for name in files:
> result=regexp.search(name)
>     print(os.path.join(dirpath,name))
> print (result)
> 
> 
> 
> 
> 
> Gregg Dotoli

I posted this because I thought it may be of help to others. This does grep 
through all the files and is very fast because the regex is compiled in Python 
, rather than sitting in some directory as an external command.
That is where the optimization comes in.

Let's close this thread.



Gregg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-25 Thread Gregg Dotoli
Grep is regular expressions. If I'm using Python, I'll use the Python modules.
Silly

Gregg

On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote:
> On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote:
> 
> > I am creating a tool to search a filesystem for one simple string.
> 
> man grep
> 
> STOP! REINVENTING! THE! WHEEL!
> 
> Your new wheel will invariably be slower and less efficient than the old 
> one.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com

-- 
https://mail.python.org/mailman/listinfo/python-list


Basic Python V3 Search Tool using RE module

2015-03-25 Thread Gregg Dotoli

This basic script will help to find 
evidence of CryptoWall on a slave drive. Although it is
just a string, more complex regex patterns can be 
replaced with the string. It is incredible how fast Python is and
how easy it has helped in quickly assessing a pool of slave drives.
I'm improving it as we speak.


Thanks for your help and patience. I'm new with Python.


import os
import re
# From the Root
topdir = "."

# Regex Pattern
pattern="DECRYPT_I"
regexp=re.compile(pattern)
for dirpath,dirnames, files in os.walk(topdir):
for name in files:
result=regexp.search(name)
print(os.path.join(dirpath,name))
    print (result)





Gregg Dotoli
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-25 Thread Gregg Dotoli
No worries Steven, 
Thanks to ALL on this thread.

Gregg



On Tuesday, March 24, 2015 at 9:43:58 PM UTC-4, Steven D'Aprano wrote:
> On Wed, 25 Mar 2015 05:13 am, gdot...@gmail.com wrote:
> 
> > The error is:
> > 
> > SyntaxError: Missing parentheses in call to 'print'
> 
> 
> I cannot imagine how the message could be more explicit: the call to print
> is missing parentheses. If you're not going to read the error messages you
> are given, you are truly going to struggle as a programmer.
> 
> Read the error message.  If you don't understand the error message, please
> say so.
> 
> And choose a relevant subject line: this has nothing to do with regexes. You
> might as well have called it "Import Python Help".
> 
> 
> -- 
> Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli

Here you go. Windows shell was easier!!!

for /f %a in (c:\gonow) do echo %a | c:\Python34\python c:\python34\unopy.py %a

Now I can use any regex pattern, I need.


On Tuesday, March 24, 2015 at 3:54:25 PM UTC-4, Rob Gaddi wrote:
> On Tue, 24 Mar 2015 12:43:38 -0700, Gregg Dotoli wrote:
> 
> > [context snipped due to top posting]
> >
> > All I need is a loop, should I bag Python and use a simple shell for 
> loop?
> 
> Honestly, yes.  You're not even using a regular expression, just a fixed 
> string you're trying to search for.  You can do the entire thing as
> 
> $ find . -type f | xargs grep DECRYPT_I
> 
> -- 
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com
> Email address domain is currently out of order.  See above to fix.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
This works fine , but I have to pipe the filename to the script python stool 
 I am creating a tool to search a filesystem for one simple string.
> I cannot get the syntax correct.
> Thank you in advance for your help.
> 
> import sys
> import re
> import os
> path='/'
> viewfiles=os.listdir(path)
> for allfiles in viewfiles:
> file= os.path.join(path, allfiles)
> text=open(file, "r")
> for line in text:
> if re.match("DECRYPT_I", line):
> print line, 
> 
> --
> This should search every file for the simple regex "DECRYPT_I"
> This is from the root down.
> 
> The error is:
> 
> SyntaxError: Missing parentheses in call to 'print'
> 
> Please help.
> Gregg Dotoli

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Thank you! But

The print error is gone, but now the script quickly finishes and doesnt walk
the OS tree or search.

Gregg 



On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote:
> I am creating a tool to search a filesystem for one simple string.
> I cannot get the syntax correct.
> Thank you in advance for your help.
> 
> import sys
> import re
> import os
> path='/'
> viewfiles=os.listdir(path)
> for allfiles in viewfiles:
> file= os.path.join(path, allfiles)
> text=open(file, "r")
> for line in text:
> if re.match("DECRYPT_I", line):
> print line, 
> 
> --
> This should search every file for the simple regex "DECRYPT_I"
> This is from the root down.
> 
> The error is:
> 
> SyntaxError: Missing parentheses in call to 'print'
> 
> Please help.
> Gregg Dotoli

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Thank you Gary, that got rid of the error, but now there is no tree walk, it 
runs and immediatley finishes. I just need to grep each file. I have this 
working with the windows "for /r %a and redirecting that to Python, but want to 
use Python only. I do have dummy files with the regex string.

Thanks again,
Gregg




On Tuesday, March 24, 2015 at 2:34:20 PM UTC-4, Gary Herron wrote:
> On 03/24/2015 11:13 AM, gdot...@gmail.com wrote:
> > I am creating a tool to search a filesystem for one simple string.
> > I cannot get the syntax correct.
> > Thank you in advance for your help.
> >
> > import sys
> > import re
> > import os
> > path='/'
> > viewfiles=os.listdir(path)
> > for allfiles in viewfiles:
> >  file= os.path.join(path, allfiles)
> > text=open(file, "r")
> > for line in text:
> >  if re.match("DECRYPT_I", line):
> >  print line,
> >
> > --
> > This should search every file for the simple regex "DECRYPT_I"
> > This is from the root down.
> >
> > The error is:
> >
> > SyntaxError: Missing parentheses in call to 'print'
> >
> > Please help.
> > Gregg Dotoli
> 
> You appear to be using Python3, but have written code for Python2.
> 
> There are a number of differences between the two, but your particular 
> error runs into the different syntax for prints.
> 
> Python2: print line # This is a statement
> Python3  print(line)  # This is a procedure call
> 
> 
> 
> -- 
> Dr. Gary Herron
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418

-- 
https://mail.python.org/mailman/listinfo/python-list