WWW::Shodan::API - Interface for the Shodan Computer Search Engine API
Version 0.021
This module provides Perl applications with easy access to the Shodan API.
use WWW::Shodan::API;
use Data::Dumper;
use constant APIKEY => '7hI5i5n07@re@L@Pik3Yd0n7b3@dumMY';
my $shodan = WWW::Shodan::API->new( APIKEY );
print Dumper $shodan->api_info;
print Dumper $shodan->profile;
print Dumper $shodan->host_ip({ IP => '8.8.8.8' });
# Search
my $results = $shodan->search({ port => 80, product => 'Apache' }, ['org', 'country'], {});
print Dumper $results;
# Alerts
my $alert = $shodan->create_alert({ name => 'My Network', ips => ['1.2.3.0/24'] });
print "Alert ID: $alert->{id}\n";In order to use the Shodan API you need to have an API key, which can be obtained for free by creating a Shodan account.
Become familiar with the Shodan REST API Documentation.
Constructor - Creates a new WWW::Shodan::API object.
my $shodan = WWW::Shodan::API->new($apikey);Takes a Shodan API key as its only argument.
Host Information - Returns all services that have been found on the given host IP.
$shodan->host_ip({ IP => '12.34.56.78' [, HISTORY => 1 [, MINIFY => 1]] })Parameters: Hash reference with keys:
IP(required): Host IP address
Search Shodan using the same query syntax as the website. May consume query credits.
my $query = { product => 'Apache', port => 80, country => 'US' };
my $facets = [ { isp => 3 }, { os => 2 }, 'version' ];
$shodan->search( $query, $facets, { PAGE => 2 } )Parameters:
$query(required): Hash reference of search filter key/value pairs.$facets(optional): Array reference of facets. Each element is either a string (e.g.'org') or a hash ref specifying a count limit (e.g.{ os => 5 }).$args(optional): Hash reference with optional keysPAGE(page number, default 1) andNO_MINIFY(if set, larger fields are not truncated).
Search Shodan without returning results - returns only the total count and facet data. Does not consume query credits.
$shodan->count( $query, $facets )Arguments are identical to $shodan->search except PAGE and NO_MINIFY are not accepted.
Break a search query string into its component tokens and filters.
$shodan->tokens({ product => 'Apache', port => 80 })List all search facets available in Shodan.
$shodan->search_facetsList all filters that can be used when searching Shodan.
$shodan->search_filtersList all ports that Shodan is currently crawling on the Internet.
$shodan->portsList all protocols that can be used for on-demand Internet scans.
$shodan->protocolsRequest Shodan to crawl one or more IPs or netblocks.
$shodan->scan([ '1.2.3.4', '5.6.7.0/24' ])Parameters: Array reference of IP addresses and/or CIDR netblocks.
Crawl the entire Internet for a specific port and protocol. Requires an academic or enterprise API plan.
$shodan->scan_internet({ port => 80, protocol => 'http' })Get a list of all scans you have submitted.
$shodan->scansGet the status of a previously submitted scan request.
$shodan->scan_status('SCAN_ID')Create a network alert to monitor a set of IPs or netblocks.
$shodan->create_alert({ name => 'My Network', ips => ['1.2.3.0/24'], expires => 0 })Parameters: Hash reference with keys:
name(required): Name of the alert.ips(required): Array reference of IPs or CIDR netblocks to monitor.expires(optional): Unix timestamp when the alert expires (0 = never).
Get a list of all network alerts you have created.
$shodan->alerts_infoGet details for a specific network alert.
$shodan->alert_info('ALERT_ID')Edit the networks monitored by an existing alert.
$shodan->edit_alert({ id => 'ALERT_ID', ips => ['1.2.3.0/24', '5.6.7.0/24'] })Delete a network alert.
$shodan->delete_alert('ALERT_ID')Get a list of available triggers that can be attached to alerts.
$shodan->alert_triggersEnable a trigger on an alert.
$shodan->enable_trigger({ id => 'ALERT_ID', trigger => 'malware' })Disable a trigger on an alert.
$shodan->disable_trigger({ id => 'ALERT_ID', trigger => 'malware' })Add an IP/port service to the whitelist for a trigger (so it doesn't generate notifications).
$shodan->add_whitelist({ id => 'ALERT_ID', trigger => 'malware', service => '1.2.3.4:80' })The service value must be in ip:port format.
Remove a service from a trigger's whitelist.
$shodan->remove_whitelist({ id => 'ALERT_ID', trigger => 'malware', service => '1.2.3.4:80' })Attach a notifier to an alert so it receives trigger notifications.
$shodan->add_notifier({ id => 'ALERT_ID', notifier_id => 'NOTIFIER_ID' })Remove a notifier from an alert.
$shodan->remove_notifier({ id => 'ALERT_ID', notifier_id => 'NOTIFIER_ID' })List all notification services you have created.
$shodan->notifiersList all available notification providers (e.g. email, Slack).
$shodan->notifier_providersGet information about a specific notifier.
$shodan->notifier_info('NOTIFIER_ID')Create a new notification service.
$shodan->create_notifier({
provider => 'email',
description => 'My alert emails',
to => 'me@example.com',
})Edit the destination address of an existing notifier.
$shodan->edit_notifier({ id => 'NOTIFIER_ID', to => 'new@example.com' })Delete a notification service.
$shodan->delete_notifier('NOTIFIER_ID')List saved search queries from the Shodan community directory.
$shodan->queries
$shodan->queries({ page => 1, sort => 'votes', order => 'desc' })Optional parameters: page (default 1), sort ('votes' or 'timestamp'), order ('asc' or 'desc').
Search the directory of saved queries.
$shodan->search_queries({ query => 'apache' })
$shodan->search_queries({ query => 'apache', page => 2 })List the most popular tags in the saved query directory.
$shodan->query_tags
$shodan->query_tags({ size => 10 })DNS Lookup - Look up the IP address for the provided list of hostnames.
$shodan->resolve_dns([ qw/google.com bing.com/ ])Reverse DNS Lookup - Look up the hostnames defined for the given list of IP addresses.
$shodan->reverse_dns([ qw/74.125.227.230 204.79.197.200/ ])Get all DNS entries and subdomains for a domain. Accepts either a plain domain string or a hash reference for optional parameters.
$shodan->domain_info('google.com')
$shodan->domain_info({ domain => 'google.com', history => 1, type => 'A' })Optional parameters: history (include historical DNS data), type (DNS record type filter, e.g. 'A', 'MX').
Get your current IP address as seen from the Internet.
$shodan->my_ipView the HTTP headers that your client sends when connecting to a web server.
$shodan->http_headersList all services and their port numbers that Shodan recognises. Returns a hash of port => service-name mappings.
$shodan->servicesReturns information about the API plan belonging to the given API key.
$shodan->api_infoReturns information about the account associated with the API key.
$shodan->profileDudley Adams, <dudleyadams at gmail.com>
Please report any bugs or feature requests to bug-www-shodan-api at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Shodan-API.
You can find documentation for this module with the perldoc command.
perldoc WWW::Shodan::APIRT: CPAN's request tracker
Search CPAN
https://github.com/Dudley5000/WWW-Shodan-API
git clone https://github.com/Dudley5000/WWW-Shodan-API.gitCopyright 2014 Dudley Adams.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: