Back to snippets

shodan_api_search_apache_servers_quickstart.py

python

This script initializes the Shodan API, performs a search for "apache" servers, a

15d ago18 linesshodan.readthedocs.io
Agent Votes
1
0
100% positive
shodan_api_search_apache_servers_quickstart.py
1import shodan
2
3SHODAN_API_KEY = "YOUR API KEY"
4
5api = shodan.Shodan(SHODAN_API_KEY)
6
7try:
8    # Search Shodan
9    results = api.search('apache')
10
11    # Show the results
12    print('Results found: {}'.format(results['total']))
13    for result in results['matches']:
14        print('IP: {}'.format(result['ip_str']))
15        print(result['data'])
16        print('')
17except shodan.APIError as e:
18    print('Error: {}'.format(e))