Created
May 11, 2010 16:24
-
-
Save sivel/397500 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib, re, sys | |
def content_match(url, match, nocase): | |
uh = urllib.urlopen(url) | |
if re.search(match, uh.read(), re.I if nocase else 0) and uh.getcode() == 200: | |
return [True, uh.geturl(), uh.getcode()] | |
else: | |
return [False, uh.geturl(), uh.getcode()] | |
def usage(): | |
print 'Usage: ', sys.argv[0], '[http://url-to-test.com] [match-content] [optional-flags]' | |
print 'Optional Flags:' | |
print '\t-i\t\tCase Insensitive Regex' | |
def main(): | |
if len(sys.argv) < 3: | |
usage() | |
return | |
try: | |
if sys.argv[3] and sys.argv[3] == '-i': | |
nocase = True | |
else: | |
nocase = False | |
except IndexError: | |
nocase = False | |
match = content_match(sys.argv[1], sys.argv[2], nocase) | |
if not match[0]: | |
print match[2], 'Failure Detected.' | |
else: | |
print match[2], 'Success Detected.' | |
if sys.argv[1] != match[1]: | |
print 'Redirect Detected:', sys.argv[1], '->', match[1] | |
return | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment