Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Complete Guide to Shodan
#2
There is some old Python 2 code in there,maybe the book is a little old and not updated.
In Python 3 must do it like this:
except shodan.APIError as e:
Updated with newer string formatting f-string.
import shodan

api = shodan.Shodan('myapikeyhere')
# Wrap the request in a try/ except block to catch errors
try:
    results = api.search('apache')
    print(f"Results found: {results['total']}")
    for result in results['matches']:
        print(f"IP: {result['ip_str']}")
        print(result['data'])
        print('')
except shodan.APIError as error:
    print(f'Error: {error}')
Reply


Messages In This Thread
Complete Guide to Shodan - by Calli - Jul-16-2022, 04:32 PM
RE: Complete Guide to Shodan - by snippsat - Jul-16-2022, 06:34 PM
RE: Complete Guide to Shodan - by Calli - Jul-16-2022, 07:08 PM
RE: Complete Guide to Shodan - by snippsat - Jul-16-2022, 07:35 PM
RE: Complete Guide to Shodan - by Calli - Jul-18-2022, 04:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New User online Guide NAP1947 1 2,155 Sep-06-2020, 04:36 PM
Last Post: Larz60+
  "Up to but not including" (My personal guide on slicing & indexing) Drone4four 5 5,535 Nov-20-2019, 09:38 PM
Last Post: newbieAuggie2019
  Looking for a Guide Through the Labyrinth stephenmolnar 1 2,646 Jan-23-2019, 08:22 PM
Last Post: Larz60+
  [split] Python Guide / Document? kumatul 2 3,613 Jan-16-2019, 12:49 AM
Last Post: micseydel
  Python Guide / Document? Qui_Ten 1 3,384 Jan-13-2019, 07:50 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020