python - How to pass the content of list one element at a time to a method? -


i have libnmap scanner script works collecting eip aws , scanning them 1 one, function collects eip looks :

def gather_public_ip():     access_key = config.get('aws','access_key')     secret_key = config.get('aws','secret_key')     regions = regions = ['us-west-2','eu-central-1','ap-southeast-1']     all_eip = []     region in regions:        client = boto3.client('ec2',aws_access_key_id=access_key,aws_secret_access_key=secret_key,region_name=region,)        addresses_dict = client.describe_addresses()        eip_dict in addresses_dict['addresses']:          if 'privateipaddress' in eip_dict:             print eip_dict['publicip']             all_eip.append(eip_dict['publicip'])        print all_eip        return all_eip 

this function returns me list looks

['22.22.124.141', '22.21.149.191', '22.11.132.122', '22.11.227.241', '22.34.28.112', '22.34.211.227', '22.27.21.233',  '22.24.199.122', '22.11.113.171', '22.21.11.8', '22.33.31.14', '22.37.19.213', '22.24.121.112', '22.32.121.132', '22.24.21.1', '22.34.72.198'] 

the main function call above method passes actual scanner function looks :

  s = scanner(config)          # execute scan , generate latest report         net_range =  gather_public_ip() # config.get('sources','networks')  ## call def         #print type(net_range)         r = s.run(net_range)         s.save()   # save pickle 

the scanner class looks like:

class scanner(object):     """container scan activies"""      def __init__(self,cp):         self.config = cp # read in configparser object settings         self.report = none      def gather_targets(self):         """gather list of targets based on configured sources"""         pass      def run(self, targets="" ,options="-pn"):         #start new nmap scan on localhost specific options          syslog.syslog("scan started")         parsed = none         nmproc = nmapprocess(targets,options)         rc = nmproc.run() 

can please me part can pass values list run method 1 one nmap can process , right sits idly

the way pass in arguments looks good. however, don't have code uses result.

try changing scanner.run this:

class scanner(object):     ...     def run(self, targets="" ,options="-pn"):         #start new nmap scan on localhost specific options          syslog.syslog("scan started")         parsed = none         nmproc = nmapprocess(targets,options)          nmproc.run_background()         while nmproc.is_running():             print("nmap scan running: etc: {0} done: {1}%".format(nmproc.etc,                                                                   nmproc.progress))             sleep(2)          print("rc: {0} output: {1}".format(nmproc.rc, nmproc.summary))  

this taken straight the docs.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo