Skip to content

Commit

Permalink
🪲 Adding error handling for connection errors. Closes #1. Hopefully.
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeinewriter committed Jul 7, 2015
1 parent 63bf3f4 commit b096246
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions wp-fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,43 @@
def main():
parser = argparse.ArgumentParser("Detects WP version from readme.html or meta tag")
parser.add_argument("-t", "--target", action="append", dest="targets", help="Add a target to scan")
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", help="Turn on verbose mode. Useful for seeing the details of errors")

args = parser.parse_args()

if args.targets != None:
scan(args.targets)
scan(args.targets, args.verbose)

def scan(targets):
def scan(targets, verbose):
for target in targets:
if not target[:5] == "http:" and not target[:6] == "https:":
target = "http://" + target
tltarget = target
tlurl = urlparse(tltarget)
target = target + '/readme.html'
url = urlparse(target)
r = requests.get(url.geturl())
if r.status_code != 200:
t = requests.get(tlurl.geturl())
w = re.compile(r'<meta name\=\"generator\" content\=\"(WordPress \d+\.\d+\.?(\d+)?)\" \/>', re.I)
n = w.search(t.text)
if n:
print "Site " + tlurl.netloc + tlurl.path + ": Running WordPress " + n.group(1)
else:
print "Site " + tlurl.netloc + tlurl.path + ": No version found"
try:
r = requests.get(url.geturl())
except requests.exceptions.ConnectionError, e:
print "Error: Unable to connect to " + tlurl.netloc
if verbose:
print e
else:
v = re.compile(r"Version (\d+\.\d+\.?(\d+)?)", re.I)
m = v.search(r.text)
if m:
print "Site " + tlurl.netloc + tlurl.path + ": Running WordPress " + m.group(1)
if r.status_code != 200:
t = requests.get(tlurl.geturl())
w = re.compile(r'<meta name\=\"generator\" content\=\"(WordPress \d+\.\d+\.?(\d+)?)\" \/>', re.I)
n = w.search(t.text)
if n:
print "Site " + tlurl.netloc + tlurl.path + ": Running WordPress " + n.group(1)
else:
print "Site " + tlurl.netloc + tlurl.path + ": No version found"
else:
print "Site " + tlurl.netloc + tlurl.path + ": No version found"
v = re.compile(r"Version (\d+\.\d+\.?(\d+)?)", re.I)
m = v.search(r.text)
if m:
print "Site " + tlurl.netloc + tlurl.path + ": Running WordPress " + m.group(1)
else:
print "Site " + tlurl.netloc + tlurl.path + ": No version found"



Expand Down

0 comments on commit b096246

Please sign in to comment.