#!/usr/bin/env python import sys import base64 from xmlrpclib import * def usage(): print "USAGE:" print "\tn4d-client -h HOST getmethods" print "\tn4d-client -h HOST [-u USER -p PASSWORD | -k KEY] -m METHOD -c CLASS [-a ARG1 ARG2 ARG3 ... ARGn]" #def usage if __name__=="__main__": # ip # user # password # method # class # parameters if len(sys.argv) < 4: usage() sys.exit(0) count=1 do_it=True error=False user=None password=None key=None class_name=None params=None get_methods=False while do_it: if sys.argv[count] == "getmethods": get_methods=True do_it=False if sys.argv[count] == "-h" or sys.argv[count] == "--host": try: host=sys.argv[count+1] except: do_it=False error=True elif sys.argv[count] == "-u" or sys.argv[count] == "--user": try: user=sys.argv[count+1] except: do_it=False error=True elif sys.argv[count] == "-p" or sys.argv[count] == "--password": try: password=sys.argv[count+1] except: do_it=False error=True elif sys.argv[count] == "-k" or sys.argv[count] == "--key": try: key=sys.argv[count+1] except: do_it=False error=True elif sys.argv[count] == "-m" or sys.argv[count] == "--method": try: method=sys.argv[count+1] except: do_it=False error=True elif sys.argv[count] == "-c" or sys.argv[count] == "--class": try: class_name=sys.argv[count+1] except: do_it=False error=True elif sys.argv[count] == "-a" or sys.argv[count] == "--arguments": try: params=[] for args in range(count+1,len(sys.argv)): params.append(sys.argv[args]) do_it=False except: do_it=False error=True elif sys.argv[count] == "--help": usage() sys.exit(0) if count < len(sys.argv)-2: count+=2 else: do_it=False #while if not error: param_list=[] if user!=None: param_list.append((user,password)) elif key!=None: param_list.append(key) else: param_list.append("") if class_name!=None: param_list.append(class_name) if params!=None: param_list.extend(params) server=ServerProxy ("https://" + host +":9779") if not get_methods: ret=getattr(server,method)(*param_list) else: ret=server.get_methods() if type(ret)==type(""): print ret.strip("\n") else: print ret