Skip to content

Instantly share code, notes, and snippets.

@achillean
achillean / wps.py
Created April 29, 2011 04:48
Wifi Positioning System
"""
WiFi Positioning System
Wrappers around the SkyHook and Google Locations APIs to resolve
wireless routers' MAC addresses (BSSID) to physical locations.
"""
try:
from json import dumps, loads
except:
from simplejson import dumps, loads
@achillean
achillean / install_shodan.sh
Created April 29, 2011 04:52
Install Shodan Library
$ easy_install shodan
# or easy_install -U shodan
# or pip install shodan
@achillean
achillean / shodan_wps_example.py
Created April 29, 2011 04:53
Shodan WPS Example
# Import the class
from shodan.wps import GoogleLocation
# Setup the object
wps_client = GoogleLocation()
# Locate the physical address of the MAC/ BSSID
address = wps_client.locate('00:1D:7E:F0:A2:B0')
@achillean
achillean / gist:5128200
Created March 10, 2013 11:14
Shodan macro for Google Spreadsheets. To use this go to Tools -> Script Editor, then copy/ paste the code. In the spreadsheet you can then do =SHODAN("cisco-ios")
/**
* Search the Shodan database using the given query. Returns the number of matches.
*/
function SHODAN(query) {
var API_KEY = 'YOUR API KEY';
var url = 'http://www.shodanhq.com/api/count?key=' + API_KEY + '&q=' + query;
var response = UrlFetchApp.fetch(url);
var data = Utilities.jsonParse(response.getContentText());
@achillean
achillean / shodan-google-spreadsheet.js
Last active May 17, 2021 12:44
Shodan macros for Google Spreadsheets. To use this go to Tools -> Script Editor, then copy/ paste the code. In the spreadsheet you can then do: =SHODAN_COUNT("cisco-ios") =SHODAN_FACET_KEYS("cisco-ios", "org") =SHODAN_FACET_VALUES("cisco-ios", "org")
var API_KEY = 'YOUR API KEY';
/**
* Search the Shodan database using the given query. Returns the number of matches.
*/
function SHODAN_COUNT(query) {
var url = 'https://api.shodan.io/shodan/host/count?key=' + API_KEY + '&query=' + query;
var response = UrlFetchApp.fetch(url);
var data = Utilities.jsonParse(response.getContentText());
@achillean
achillean / simple-export.py
Last active April 16, 2022 16:29
A simple script to search Shodan and output the results as JSON-encoded banners; each line corresponds to a single banner.
#!/usr/bin/env python
"""
A simple script to search Shodan and output the results as JSON-encoded banners;
each line corresponds to a single banner.
Warning: This will use up query credits because it pages through the results!
Usage: python simple-export.py <search query>
"""
# Install via "easy_install shodan"
@achillean
achillean / Shodan bitcoin sample banner
Created February 21, 2014 07:07
Here is a sample banner collected from a Bitcoin server. Note that it includes a list of up to 1000 peers' IP addresses and ports.
{
"os": null,
"timestamp": "2014-02-21T06:49:56.251378",
"isp": "Comcast Cable",
"asn": "AS7922",
"hostnames": ["c-69-180-254-194.hsd1.tn.comcast.net"],
"location": {
"city": "Goodlettsville",
"region_name": null,
"area_code": 615,
@achillean
achillean / shodan-stream.py
Created June 12, 2014 23:43
Basic code template for accessing the Shodan Streaming API using Python
#!/usr/bin/env python
#
# shodan-stream.py
# Read a firehose/ stream of 1% of the data that Shodan collects in real-time.
#
# WARNING: This script only works with people that have a subscription API plan!
# And by default the Streaming API only returns 1% of the data that Shodan gathers.
# If you wish to have more access please contact us at support@shodan.io for pricing
# information.
#
@achillean
achillean / camscan.py
Created July 25, 2014 14:26
An updated version of the camscan.py script to search Shodan for webcams. This script uses the new Shodan API documented at https://developer.shodan.io as well as the new search_cursor() method to easily iterate over results.
import shodan
import socket
# Configuration options
API_KEY = 'YOUR API KEY'
SEARCH_QUERY = 'netcam'
CONNECTION_TIMEOUT = 1.5
def is_camera(ip_str):
"""Check whether the given IP operates a valid webcam by checking for the existence of a URL."""
@achillean
achillean / threatnet-stream.py
Created January 7, 2015 19:22
How to read events from the Threatnet stream. Note: make sure you have the latest version of the Shodan Python library installed (>=1.2.3).
import shodan.threatnet
# Configuration
API_KEY = "Please enter your API key here"
# Create the object that interfaces with the Threatnet API
tnet = shodan.threatnet.Threatnet(API_KEY)
# Get a stream of events and print them to stdout
for event in tnet.stream.events():