
def xmlcrack():
    '''
    @description: Sends hash list to remote XMLRPC server for cracking. Crackserver.py must be running on the remote host.
    @author: original code by Stephen Haywood aka averagesecurityguy
    @short: xmlrpc crack client (-x filename hashtype)
    '''
    if len(sys.argv) <=3:
        print("[!] Must specify a filename and hashtype!")
        sys.exit()

    import time
    try:
        import xmlrpclib
    except ImportError:
        print("[!] Python library XMLRPC is not installed!")
        sys.exit(0)    

    data = []
    filename = sys.argv[2]
    hashtype = sys.argv[3]

    try:
    #Open the hash file and convert it to an array before sending it in the
    #XMLRPC request.
        file = open(filename, 'rb')
        for line in file:
            data.append(line.rstrip('\r\n'))
        file.close()
    except Exception, err:
        print "Error opening file " + filename + ": " + str(err)

    # Open connection to xmlrpc server
    server = ("http://"+RHOST+":"+str(RPORT))
    try:
        s = xmlrpclib.ServerProxy(server)
    except:
        print "Error opening connection to server " + server + ": " + str(err)

    # Send request to server and receive ID
    id, msg = s.crack(data, hashtype)

    if id == 0:
        print msg
    else:
        # Poll server for completion status and results using ID.
        complete = False
        wait = 10
        while True:
            time.sleep(wait)
            complete, results = s.results(id)
            if results != []:
                for r in results:
                    print r.rstrip('\r\n')
            if complete: break    
