pythonpython-3.xshodan

Shodan.py search doesn't print full result set when printing matches list


I'm trying to print out a full result list for a specific query I am performing, in the format IP:PORT. However it only prints a partial amount.

results['total'] prints 1799 (which is also the result amount when the search is performed on the Shodan website), however when printing the actual matches out, it only prints 99 results.

It probably is something elementary such as not showing all the result pages. I have a Shodan educational account.

from shodan import Shodan

api = Shodan('APIKEY')

# Search Shodan
results = api.search('SearchQuery')

# Results found: 1799 
print('Results found: {}'.format(results['total']))

# Prints 99 results. 
for result in results['matches']:
    print(str(result['ip_str']) + ":" + str(result['port']))

Expected: 1799 results Actual: 100 results

Thanks in advance!


Solution

  • Shodan only returns the first page which contains 100 results, any further queries for pages beyond will cost 1 query credit.

    To get more pages:

    api.search('SearchQuery', page=2) etc...