pythonpython-2.7shodan

Iterate Through Dictionary Values, Assign to Variable


I'm trying to iterate through an imported .csv file and assign each value within a column to a variable. The idea being to use that variable to conduct a search of the Shodan API, print the search results to the screen and then move on to the value in the next row in the column, assign it to the variable, do the search, and so on.

Here's what I've cobbled together from what I've found so far....

import csv

# Initialize the API
from shodan import WebAPI
api = WebAPI("My Shodan Key")

# Open csv file

with open('C:\pythonfiles\sccm.csv', 'rb') as reader:
    sccmtable = csv.reader(reader, delimiter=';')
    #for row in sccmtable:
    #print ', '.join(row)

for row in sccmtable:
    for value in row:
        edbresults = api.exploitdb.search(value)
        print (edbresults)

It seems as if this is the correct start, as I can print the content of the newly imported csv to the screen, but I'm not sure how to take the next step. Any help is greatly appreciated.

Best regards.


Solution

  • In order to search each value in each row individually, do:

    for row in reader:
        for value in row:
            edbresults = api.exploitdb.search(value)
            print (edbresults)