File: basic-search.rst

package info (click to toggle)
python-shodan 1.31.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 408 kB
  • sloc: python: 2,818; makefile: 150
file content (37 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Basic Shodan Search
-------------------

.. code-block:: python
	
	#!/usr/bin/env python
	#
	# shodan_ips.py
	# Search SHODAN and print a list of IPs matching the query
	#
	# Author: achillean
	
	import shodan
	import sys
	
	# Configuration
	API_KEY = "YOUR_API_KEY"
	
	# Input validation
	if len(sys.argv) == 1:
		print 'Usage: %s <search query>' % sys.argv[0]
		sys.exit(1)
	
	try:
		# Setup the api
		api = shodan.Shodan(API_KEY)
	
		# Perform the search
		query = ' '.join(sys.argv[1:])
		result = api.search(query)
		
		# Loop through the matches and print each IP
		for service in result['matches']:
			print service['ip_str']
	except Exception as e:
		print 'Error: %s' % e
		sys.exit(1)