| 1 | package WWW::Shodan::API; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | our $VERSION = '0.021'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use constant BASE_URL => 'https://api.shodan.io'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 5 | my ( $class, $apikey ) = @_; | |||||||||||||||||||||||||||
| 20 | 5 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||
| 21 | 5 | my $json = JSON->new->allow_nonref; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5 | my $self = { | |||||||||||||||||||||||||||
| 24 | APIKEY => $apikey, | ||||||||||||||||||||||||||||
| 25 | UA => $ua, | ||||||||||||||||||||||||||||
| 26 | JSON => $json, | ||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | 5 | bless $self, $class; | |||||||||||||||||||||||||||
| 29 | 5 | return $self; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 50 | ▶ | sub _ua { | ||||||||||||||||||||||||||
|
Subroutine
_ua: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 50 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 50 | return $self->{UA}; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 53 | ▶ | sub _json { | ||||||||||||||||||||||||||
|
Subroutine
_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 53 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 53 | return $self->{JSON}; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 50 | ▶ | sub _request { | ||||||||||||||||||||||||||
|
Subroutine
_request: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 43 | 50 | my ( $self, $method, $path, %opts ) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 50 | my $uri = URI->new( BASE_URL . $path ); | |||||||||||||||||||||||||||
| 46 | 50 | ▶ | my %query = ( key => $self->_get_apikey, %{ $opts{query} // {} } ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$opts{"query"} // {}
MC/DC100%1/1
$opts{"query"} // {}
$opts{"query"}
Truth table100%2/2
A
A= $opts{"query"}
| |||||||||||||||||||||||||||||
| 47 | 50 | $uri->query_form( %query ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 50 | my $req = HTTP::Request->new( $method => $uri->as_string ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 50 | ▶ | if ( $opts{json} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 3 | $req->header( 'Content-Type' => 'application/json' ); | |||||||||||||||||||||||||||
| 53 | 3 | $req->content( $self->_json->encode( $opts{json} ) ); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | elsif ( $opts{form} ) { | ||||||||||||||||||||||||||||
| 56 | 4 | my $tmp = URI->new( 'http://x/' ); | |||||||||||||||||||||||||||
| 57 | 4 | $tmp->query_form( %{ $opts{form} } ); | |||||||||||||||||||||||||||
| 58 | 4 | $req->header( 'Content-Type' => 'application/x-www-form-urlencoded' ); | |||||||||||||||||||||||||||
| 59 | 4 | ▶ | $req->content( $tmp->query // '' ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$tmp->query // ""
MC/DC0%0/1
$tmp->query // ""
$tmp->query
Truth table50%1/2
A
A= $tmp->query
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 50 | my $response = $self->_ua->request( $req ); | |||||||||||||||||||||||||||
| 63 | 50 | my $data; | |||||||||||||||||||||||||||
| 64 | 50 | eval { $data = $self->_json->decode( $response->decoded_content ) }; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 50 | ▶ | if ( $response->is_success && defined $data ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$response->is_success and defined $data
MC/DC50%1/2
$response->is_success and defined $data
$response->is_success
defined $data
Truth table66%2/3
A and B
A= $response->is_successB= defined $data
| |||||||||||||||||||||||||||||
| 67 | 48 | return $data; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||
| 70 | croak sprintf "%s - %s", | ||||||||||||||||||||||||||||
| 71 | $response->status_line, | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | ( $data && $data->{error} ) ? $data->{error} : 'API provided no error message'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$data and $data->{"error"}
MC/DC50%1/2
$data and $data->{"error"}
$data
$data->{"error"}
Truth table66%2/3
A and B
A= $dataB= $data->{"error"}
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | sub api_info { | ||||||||||||||||||||||||||
|
Subroutine
api_info: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 4 | my $result = $self->_request( 'GET', '/api-info' ); | |||||||||||||||||||||||||||
| 79 | 2 | for my $value ( values %$result ) { | |||||||||||||||||||||||||||
| 80 | 9 | ▶ | next unless JSON::is_bool( $value ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $value = ( $value ? 'true' : 'false' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 2 | return $result; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub resolve_dns { | ||||||||||||||||||||||||||
|
Subroutine
resolve_dns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 1 | my ( $self, $hostnames ) = @_; | |||||||||||||||||||||||||||
| 88 | 1 | my $hosts = join( ",", @$hostnames ); | |||||||||||||||||||||||||||
| 89 | 1 | return $self->_request( 'GET', '/dns/resolve', query => { hostnames => $hosts } ); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | ▶ | sub reverse_dns { | ||||||||||||||||||||||||||
|
Subroutine
reverse_dns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 1 | my ( $self, $ips ) = @_; | |||||||||||||||||||||||||||
| 94 | 1 | return $self->_request( 'GET', '/dns/reverse', | |||||||||||||||||||||||||||
| 95 | query => { ips => join( ',', @$ips ) } ); | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | sub host_ip { | ||||||||||||||||||||||||||
|
Subroutine
host_ip: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 2 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 100 | 2 | my %query; | |||||||||||||||||||||||||||
| 101 | 2 | ▶ | $query{history} = 'true' if $args->{HISTORY}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 2 | ▶ | $query{minify} = 'true' if $args->{MINIFY}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 2 | return $self->_request( 'GET', "/shodan/host/$args->{IP}", query => \%query ); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 4 | ▶ | sub _build_query_str { | ||||||||||||||||||||||||||
|
Subroutine
_build_query_str: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 107 | 4 | my ( $query ) = @_; | |||||||||||||||||||||||||||
| 108 | 4 | ▶ | return '' unless ref $query eq 'HASH' && scalar keys %$query; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $query eq "HASH" and scalar keys %$query
MC/DC0%0/1
ref $query eq "HASH" and scalar keys %$query
ref $query eq "HASH"
Truth table50%1/2
A
A= ref $query eq "HASH"
| |||||||||||||||||||||||||||||
| 109 | 4 | return join( ' ', map { "$_:$query->{$_}" } keys %$query ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 3 | ▶ | sub _build_facets_str { | ||||||||||||||||||||||||||
|
Subroutine
_build_facets_str: called CC=5 SCAR=27.4
| |||||||||||||||||||||||||||||
| 113 | 3 | my ( $facets ) = @_; | |||||||||||||||||||||||||||
| 114 | 3 | ▶ | return '' unless ref $facets eq 'ARRAY' && scalar @$facets; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $facets eq "ARRAY" and scalar @$facets
MC/DC0%0/1
ref $facets eq "ARRAY" and scalar @$facets
ref $facets eq "ARRAY"
Truth table50%1/2
A
A= ref $facets eq "ARRAY"
| |||||||||||||||||||||||||||||
| 115 | 0 | my @parts; | |||||||||||||||||||||||||||
| 116 | 0 | for my $f ( @$facets ) { | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ( ref $f eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | my ( $k ) = keys %$f; | |||||||||||||||||||||||||||
| 119 | 0 | my $v = $f->{$k}; | |||||||||||||||||||||||||||
| 120 | 0 | push @parts, "$k:$v"; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||
| 123 | 0 | push @parts, $f; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 0 | return join( ',', @parts ); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 2 | ▶ | sub search { | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 2 | my ( $self, $query, $facet, $args ) = @_; | |||||||||||||||||||||||||||
| 131 | 2 | ▶ | $facet //= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$facet //= []
MC/DC0%0/1
$facet //= []
$facet
Truth table50%1/2
A
A= $facet
| |||||||||||||||||||||||||||||
| 132 | 2 | ▶ | $args //= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args //= {}
MC/DC0%0/1
$args //= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||
| 133 | 2 | my %params; | |||||||||||||||||||||||||||
| 134 | 2 | my $qstr = _build_query_str( $query ); | |||||||||||||||||||||||||||
| 135 | 2 | ▶ | $params{query} = $qstr if $qstr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 2 | my $fstr = _build_facets_str( $facet ); | |||||||||||||||||||||||||||
| 137 | 2 | ▶ | $params{facets} = $fstr if $fstr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 2 | ▶ | $params{page} = $args->{PAGE} if defined $args->{PAGE}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 2 | ▶ | $params{minify} = 'false' if defined $args->{NO_MINIFY}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 2 | return $self->_request( 'GET', '/shodan/host/search', query => \%params ); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | ▶ | sub tokens { | ||||||||||||||||||||||||||
|
Subroutine
tokens: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 1 | my ( $self, $query ) = @_; | |||||||||||||||||||||||||||
| 145 | 1 | my %params; | |||||||||||||||||||||||||||
| 146 | 1 | my $qstr = _build_query_str( $query ); | |||||||||||||||||||||||||||
| 147 | 1 | ▶ | $params{query} = $qstr if $qstr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 1 | return $self->_request( 'GET', '/shodan/host/search/tokens', query => \%params ); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub count { | ||||||||||||||||||||||||||
|
Subroutine
count: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 1 | my ( $self, $query, $facet ) = @_; | |||||||||||||||||||||||||||
| 153 | 1 | ▶ | $facet //= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$facet //= []
MC/DC0%0/1
$facet //= []
$facet
Truth table50%1/2
A
A= $facet
| |||||||||||||||||||||||||||||
| 154 | 1 | my %params; | |||||||||||||||||||||||||||
| 155 | 1 | my $qstr = _build_query_str( $query ); | |||||||||||||||||||||||||||
| 156 | 1 | ▶ | $params{query} = $qstr if $qstr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 1 | my $fstr = _build_facets_str( $facet ); | |||||||||||||||||||||||||||
| 158 | 1 | ▶ | $params{facets} = $fstr if $fstr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 1 | return $self->_request( 'GET', '/shodan/host/count', query => \%params ); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 1 | ▶ | sub my_ip { | ||||||||||||||||||||||||||
|
Subroutine
my_ip: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | 1 | return $self->_request( 'GET', '/tools/myip' ); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | ▶ | sub services { | ||||||||||||||||||||||||||
|
Subroutine
services: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 169 | 1 | return $self->_request( 'GET', '/shodan/services' ); | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # Search additions | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 1 | ▶ | sub search_facets { | ||||||||||||||||||||||||||
|
Subroutine
search_facets: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 176 | 1 | return $self->_request( 'GET', '/shodan/host/search/facets' ); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | ▶ | sub search_filters { | ||||||||||||||||||||||||||
|
Subroutine
search_filters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 180 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 181 | 1 | return $self->_request( 'GET', '/shodan/host/search/filters' ); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # On-Demand Scanning | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | ▶ | sub ports { | ||||||||||||||||||||||||||
|
Subroutine
ports: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 187 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 188 | 1 | return $self->_request( 'GET', '/shodan/ports' ); | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 1 | ▶ | sub protocols { | ||||||||||||||||||||||||||
|
Subroutine
protocols: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 193 | 1 | return $self->_request( 'GET', '/shodan/protocols' ); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub scan { | ||||||||||||||||||||||||||
|
Subroutine
scan: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 1 | my ( $self, $ips ) = @_; | |||||||||||||||||||||||||||
| 198 | 1 | return $self->_request( 'POST', '/shodan/scan', | |||||||||||||||||||||||||||
| 199 | form => { ips => join( ',', @$ips ) } ); | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 1 | ▶ | sub scan_internet { | ||||||||||||||||||||||||||
|
Subroutine
scan_internet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 204 | return $self->_request( 'POST', '/shodan/scan/internet', | ||||||||||||||||||||||||||||
| 205 | 1 | form => { port => $args->{port}, protocol => $args->{protocol} } ); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 1 | ▶ | sub scans { | ||||||||||||||||||||||||||
|
Subroutine
scans: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 209 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 210 | 1 | return $self->_request( 'GET', '/shodan/scans' ); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 1 | ▶ | sub scan_status { | ||||||||||||||||||||||||||
|
Subroutine
scan_status: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 1 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 215 | 1 | return $self->_request( 'GET', "/shodan/scan/$id" ); | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # Network Alerts | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 2 | ▶ | sub create_alert { | ||||||||||||||||||||||||||
|
Subroutine
create_alert: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 221 | 2 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 222 | my %body = ( | ||||||||||||||||||||||||||||
| 223 | name => $args->{name}, | ||||||||||||||||||||||||||||
| 224 | filters => { ip => $args->{ips} }, | ||||||||||||||||||||||||||||
| 225 | 2 | ); | |||||||||||||||||||||||||||
| 226 | 2 | ▶ | $body{expires} = $args->{expires} if defined $args->{expires}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 2 | return $self->_request( 'POST', '/shodan/alert', json => \%body ); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 1 | ▶ | sub alerts_info { | ||||||||||||||||||||||||||
|
Subroutine
alerts_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 231 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 232 | 1 | return $self->_request( 'GET', '/shodan/alert/info' ); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 1 | ▶ | sub alert_info { | ||||||||||||||||||||||||||
|
Subroutine
alert_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 236 | 1 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 237 | 1 | return $self->_request( 'GET', "/shodan/alert/$id/info" ); | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 1 | ▶ | sub edit_alert { | ||||||||||||||||||||||||||
|
Subroutine
edit_alert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 241 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 242 | return $self->_request( 'POST', "/shodan/alert/$args->{id}", | ||||||||||||||||||||||||||||
| 243 | 1 | json => { filters => { ip => $args->{ips} } } ); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 1 | ▶ | sub delete_alert { | ||||||||||||||||||||||||||
|
Subroutine
delete_alert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 247 | 1 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 248 | 1 | return $self->_request( 'DELETE', "/shodan/alert/$id" ); | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 1 | ▶ | sub alert_triggers { | ||||||||||||||||||||||||||
|
Subroutine
alert_triggers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 253 | 1 | return $self->_request( 'GET', '/shodan/alert/triggers' ); | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 1 | ▶ | sub enable_trigger { | ||||||||||||||||||||||||||
|
Subroutine
enable_trigger: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 257 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 258 | 1 | return $self->_request( 'PUT', "/shodan/alert/$args->{id}/trigger/$args->{trigger}" ); | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 1 | ▶ | sub disable_trigger { | ||||||||||||||||||||||||||
|
Subroutine
disable_trigger: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 262 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 263 | 1 | return $self->_request( 'DELETE', "/shodan/alert/$args->{id}/trigger/$args->{trigger}" ); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 1 | ▶ | sub add_whitelist { | ||||||||||||||||||||||||||
|
Subroutine
add_whitelist: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 267 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 268 | 1 | my $svc = uri_escape( $args->{service} ); | |||||||||||||||||||||||||||
| 269 | 1 | return $self->_request( 'PUT', | |||||||||||||||||||||||||||
| 270 | "/shodan/alert/$args->{id}/trigger/$args->{trigger}/ignore/$svc" ); | ||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 1 | ▶ | sub remove_whitelist { | ||||||||||||||||||||||||||
|
Subroutine
remove_whitelist: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 274 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 275 | 1 | my $svc = uri_escape( $args->{service} ); | |||||||||||||||||||||||||||
| 276 | 1 | return $self->_request( 'DELETE', | |||||||||||||||||||||||||||
| 277 | "/shodan/alert/$args->{id}/trigger/$args->{trigger}/ignore/$svc" ); | ||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 1 | ▶ | sub add_notifier { | ||||||||||||||||||||||||||
|
Subroutine
add_notifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 281 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 282 | 1 | return $self->_request( 'PUT', "/shodan/alert/$args->{id}/notifier/$args->{notifier_id}" ); | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 1 | ▶ | sub remove_notifier { | ||||||||||||||||||||||||||
|
Subroutine
remove_notifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 286 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 287 | 1 | return $self->_request( 'DELETE', "/shodan/alert/$args->{id}/notifier/$args->{notifier_id}" ); | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # Notifiers | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 1 | ▶ | sub notifiers { | ||||||||||||||||||||||||||
|
Subroutine
notifiers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 293 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 294 | 1 | return $self->_request( 'GET', '/notifier' ); | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 1 | ▶ | sub notifier_providers { | ||||||||||||||||||||||||||
|
Subroutine
notifier_providers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 298 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 299 | 1 | return $self->_request( 'GET', '/notifier/provider' ); | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 1 | ▶ | sub notifier_info { | ||||||||||||||||||||||||||
|
Subroutine
notifier_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 303 | 1 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 304 | 1 | return $self->_request( 'GET', "/notifier/$id" ); | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 1 | ▶ | sub create_notifier { | ||||||||||||||||||||||||||
|
Subroutine
create_notifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 308 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 309 | return $self->_request( 'POST', '/notifier', | ||||||||||||||||||||||||||||
| 310 | form => { | ||||||||||||||||||||||||||||
| 311 | provider => $args->{provider}, | ||||||||||||||||||||||||||||
| 312 | description => $args->{description}, | ||||||||||||||||||||||||||||
| 313 | to => $args->{to}, | ||||||||||||||||||||||||||||
| 314 | 1 | } ); | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 1 | ▶ | sub edit_notifier { | ||||||||||||||||||||||||||
|
Subroutine
edit_notifier: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 318 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 319 | 1 | my %body; | |||||||||||||||||||||||||||
| 320 | 1 | ▶ | $body{provider} = $args->{provider} if defined $args->{provider}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 1 | ▶ | $body{description} = $args->{description} if defined $args->{description}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 1 | ▶ | $body{to} = $args->{to} if defined $args->{to}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 1 | return $self->_request( 'PUT', "/notifier/$args->{id}", form => \%body ); | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 1 | ▶ | sub delete_notifier { | ||||||||||||||||||||||||||
|
Subroutine
delete_notifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 327 | 1 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 328 | 1 | return $self->_request( 'DELETE', "/notifier/$id" ); | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | # Directory Methods | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 2 | ▶ | sub queries { | ||||||||||||||||||||||||||
|
Subroutine
queries: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 334 | 2 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 335 | 2 | ▶ | $args //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args //= {}
MC/DC100%1/1
$args //= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||
| 336 | 2 | return $self->_request( 'GET', '/shodan/query', query => $args ); | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 1 | ▶ | sub search_queries { | ||||||||||||||||||||||||||
|
Subroutine
search_queries: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 340 | 1 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 341 | 1 | ▶ | $args //= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args //= {}
MC/DC0%0/1
$args //= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||
| 342 | 1 | return $self->_request( 'GET', '/shodan/query/search', query => $args ); | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 2 | ▶ | sub query_tags { | ||||||||||||||||||||||||||
|
Subroutine
query_tags: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 346 | 2 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 347 | 2 | ▶ | $args //= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args //= {}
MC/DC100%1/1
$args //= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||
| 348 | 2 | return $self->_request( 'GET', '/shodan/query/tags', query => $args ); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | # Account Methods | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 1 | ▶ | sub profile { | ||||||||||||||||||||||||||
|
Subroutine
profile: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 354 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 355 | 1 | return $self->_request( 'GET', '/account/profile' ); | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | # DNS additions | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 2 | ▶ | sub domain_info { | ||||||||||||||||||||||||||
|
Subroutine
domain_info: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 361 | 2 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 362 | 2 | ▶ | $args = { domain => $args } unless ref $args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | 2 | my $domain = delete $args->{domain}; | |||||||||||||||||||||||||||
| 364 | 2 | return $self->_request( 'GET', "/dns/domain/$domain", query => $args ); | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | # Utility additions | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 1 | ▶ | sub http_headers { | ||||||||||||||||||||||||||
|
Subroutine
http_headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 370 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 371 | 1 | return $self->_request( 'GET', '/tools/httpheaders' ); | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 50 | ▶ | sub _get_apikey { | ||||||||||||||||||||||||||
|
Subroutine
_get_apikey: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 375 | 50 | my $self = shift; | |||||||||||||||||||||||||||
| 376 | 50 | return $self->{APIKEY}; | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 6 | 1; # End of WWW::Shodan::API | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | __DATA__ | ||||||||||||||||||||||||||||