Shodan - Python Syntax to use "Info" Tag

278 views Asked by At

So I'm currently working on a script using Shodan in Python using import shodan. The documentation around isn't the best so id thought I'd bring my issue here.

Using the Shodan CLI there is a command known as Shodan Info which displays the number of search credits that your account has remaining.

When looking at the Shodan Documentation i can see that there is an info() tag but whenever I use it there has been an error.

Does anyone know the correct syntax for using info in a python script to display the number of credits an account has?

Errors i have received:

ipinfo = shodan.info()
print (ipinfo)

Error

Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XX Documents/XXXX/Working 
                                             Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.info()
AttributeError: module 'shodan' has no attribute 'info'

And

ipinfo = shodan.Shodan(info())
print (ipinfo)

Error

Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XXXXDocuments/XXXXXX/Working 
                                             Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.Shodan(info())
NameError: name 'info' is not defined
2

There are 2 answers

3
achillean On BEST ANSWER

You need to instantiate the Shodan class and then you will be able to use its Shodan.info() method. Here is how it looks in the official command-line interface:

https://github.com/achillean/shodan-python/blob/master/shodan/__main__.py#L364

Here's a short script that prints the current account usage information:

import pprint
import shodan

key = 'YOUR API KEY'
api = shodan.Shodan(key)
results = api.info()
pprint.pprint(results)
2
Seaver Olson On

shodan does not express how to use info. heres a breif example of how to set up shodan info

import shodan
api = shodan.Shodan('YOUR API KEY')

info = api.host('8.8.8.8')
shodan info