What's wrong with this script?

This is the place for queries that don't fit in any of the other categories.

What's wrong with this script?

Postby level0_coder » Tue Dec 10, 2013 8:23 pm

Code: Select all
##!/usr/bin/python
import urllib, sys, argparse

parser = argparse.ArgumentParser()
parser.add_argument('-pw', action='store_true', help='get pw only')
parser.add_argument('-hash', action='store_true', help='get hash only')
parser.add_argument('-both', action='store_true', help='get both hash & pw')
parser.add_argument('-v', action='store_true', help='verbose')
parser.add_argument('pagenum', nargs='+', help='page number required')
args=parser.parse_args()

def main():
    url = 'http://www.md5this.com/list.php?page='
    pagenum=min([int(i) for i in args.pagenum])
    start,stop=int(pagenum),int(pagenum)
    outname=str(pagenum)
    hashes,passes,output=[],[],''
    if len(args.pagenum)>1:
        stop = int(max([int(i) for i in args.pagenum]))
        outname="%d-%d"%(start,stop)
    for pagenum in range(start,stop+1):
        pagenum=str(pagenum)
        try:
            if args.v: print 'working on page '+pagenum
            page = urllib.urlopen(url+pagenum)
            page=page.read().split('\n')
            for line in page:
                if '200px' in line:
                    idx=line.index(';">')
                    hashes.append(line[idx+3:idx+35])
                if '280px' in line:
                    idx=line.index(';">')
                    try:
                        end = line.index('</td>')
                        passes.append(line[idx+3:end])
                    except:
                        passes.append(line[idx+3:])
            if args.both:
                for pair in zip(hashes,passes):
                    output+='%s %s\n' %(pair[0],pair[1])
            elif args.hash:
                for h in hashes: output+='%s\n'%h
            elif args.pw:
                for p in passes: output+='%s\n'%p
        except:
            outname=str(int(pagenum)-1)
            print 'error on page %s, writing %d-%d'%(pagenum,start,stop)
            break
    with open(outname+'.txt','w') as f: f.write(output)

main()


the script grabs hashes from this link http://md5this.com/list.php?page=[NumberOfPage]

The problem is that this script grabs the content from the same pages twice for example if i ran the code
python script.py -hash 2 3
it grabs the hashes from page 2 twice!

can somebody PLEASE fix the script for me, i've been trying for 2 days now :(

please help.
Last edited by stranac on Tue Dec 10, 2013 8:34 pm, edited 1 time in total.
Reason: First post lock.
level0_coder
 
Posts: 1
Joined: Tue Dec 10, 2013 8:17 pm

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 4 guests

cron