| 1 | # see POD at the bottom for documentation | ||||||||||||||||||||
| 2 | package Net::Wigle; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use 5.010000; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | require Exporter; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | our @ISA = qw( | |||||||||||||||||||
| 15 | Exporter | ||||||||||||||||||||
| 16 | LWP::UserAgent | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||
| 20 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||
| 21 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | # This allows declaration use Net::Wigle ':all'; | ||||||||||||||||||||
| 24 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||
| 25 | # will save memory. | ||||||||||||||||||||
| 26 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||
| 27 | ) ] ); | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | our @EXPORT = qw( | |||||||||||||||||||
| 32 | ); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 1 | our $VERSION = '0.07'; | |||||||||||||||||||
| 35 | 1 | our $url_query_base = 'https://wigle.net/api/v1/jsonSearch'; | |||||||||||||||||||
| 36 | 1 | our $url_login = 'https://wigle.net/api/v1/jsonUser'; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 39 | 1 | my $proto = shift; | |||||||||||||||||||
| 40 | 1 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 41 | 1 | my $self = {}; | |||||||||||||||||||
| 42 | 1 | bless $self, $class; | |||||||||||||||||||
| 43 | 1 | $self->requests_redirectable(['GET', 'HEAD', 'POST']); | |||||||||||||||||||
| 44 | 1 | return $self; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # purpose : login to wigle.net | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | sub log_in { | ||||||||||||||||||
|
Subroutine
log_in: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||||||||||
| 51 | 0 | my %args = validate @_, { | |||||||||||||||||||
| 52 | user => { type => SCALAR, }, | ||||||||||||||||||||
| 53 | pass => { type => SCALAR, }, | ||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||
| 55 | 0 | ▶ | unless ($self->cookie_jar) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | $self->cookie_jar({}); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | my $form = { | ||||||||||||||||||||
| 59 | credential_0 => $args{user}, | ||||||||||||||||||||
| 60 | credential_1 => $args{pass}, | ||||||||||||||||||||
| 61 | 0 | destination => '/https://wigle.net', | |||||||||||||||||||
| 62 | noexpire => 'checked', | ||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||
| 64 | 0 | my $response = $self->post($url_login, $form); | |||||||||||||||||||
| 65 | 0 | ▶ | unless ($response->is_success) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 0 | return undef; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | 0 | return $self->cookie_jar; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | # purpose : used to return a parsed/scraped html table | ||||||||||||||||||||
| 72 | # now it just returns the parsed json | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | ▶ | sub query { | ||||||||||||||||||
|
Subroutine
query: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||
| 76 | 0 | my %args = validate @_, { | |||||||||||||||||||
| 77 | user => { | ||||||||||||||||||||
| 78 | type => SCALAR, | ||||||||||||||||||||
| 79 | }, | ||||||||||||||||||||
| 80 | pass => { | ||||||||||||||||||||
| 81 | type => SCALAR, | ||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||
| 83 | variance => { | ||||||||||||||||||||
| 84 | default => '0.010', | ||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||
| 86 | latrange1 => { | ||||||||||||||||||||
| 87 | optional => 1, | ||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||
| 89 | latrange2 => { | ||||||||||||||||||||
| 90 | optional => 1, | ||||||||||||||||||||
| 91 | }, | ||||||||||||||||||||
| 92 | longrange1 => { | ||||||||||||||||||||
| 93 | optional => 1, | ||||||||||||||||||||
| 94 | }, | ||||||||||||||||||||
| 95 | longrange2 => { | ||||||||||||||||||||
| 96 | optional => 1, | ||||||||||||||||||||
| 97 | }, | ||||||||||||||||||||
| 98 | addresscode => { | ||||||||||||||||||||
| 99 | optional => 1, | ||||||||||||||||||||
| 100 | }, | ||||||||||||||||||||
| 101 | statecode => { | ||||||||||||||||||||
| 102 | optional => 1, | ||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||
| 104 | zipcode => { | ||||||||||||||||||||
| 105 | optional => 1, | ||||||||||||||||||||
| 106 | }, | ||||||||||||||||||||
| 107 | pagestart => { | ||||||||||||||||||||
| 108 | optional => 1, | ||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||
| 110 | lastupdt => { | ||||||||||||||||||||
| 111 | optional => 1, | ||||||||||||||||||||
| 112 | }, | ||||||||||||||||||||
| 113 | netid => { | ||||||||||||||||||||
| 114 | optional => 1, | ||||||||||||||||||||
| 115 | }, | ||||||||||||||||||||
| 116 | ssid => { | ||||||||||||||||||||
| 117 | optional => 1, | ||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||
| 119 | freenet => { | ||||||||||||||||||||
| 120 | optional => 1, | ||||||||||||||||||||
| 121 | }, | ||||||||||||||||||||
| 122 | paynet => { | ||||||||||||||||||||
| 123 | optional => 1, | ||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||
| 125 | dhcp => { | ||||||||||||||||||||
| 126 | optional => 1, | ||||||||||||||||||||
| 127 | }, | ||||||||||||||||||||
| 128 | onlymine => { | ||||||||||||||||||||
| 129 | optional => 1, | ||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||
| 131 | Query => { | ||||||||||||||||||||
| 132 | default => 'Query', | ||||||||||||||||||||
| 133 | }, | ||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||
| 135 | my $cookie_jar = $self->log_in( | ||||||||||||||||||||
| 136 | user => $args{user}, | ||||||||||||||||||||
| 137 | pass => $args{pass}, | ||||||||||||||||||||
| 138 | 0 | ); | |||||||||||||||||||
| 139 | 0 | ▶ | unless ($cookie_jar) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 140 | 0 | return undef; | |||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | 0 | delete $args{user}; | |||||||||||||||||||
| 143 | 0 | delete $args{pass}; | |||||||||||||||||||
| 144 | 0 | my $response = $self->query_raw(%args); | |||||||||||||||||||
| 145 | 0 | ▶ | unless ($response->is_success) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 146 | 0 | return undef; | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | 0 | return from_json($response->decoded_content); | |||||||||||||||||||
| 149 | 0 | my $string_search_response = $response->as_string; | |||||||||||||||||||
| 150 | 0 | my @records; | |||||||||||||||||||
| 151 | #$string_search_response =~ qr/.*\<tr\s+class="search"\s*\>(.*?)\<\/tr.*/xmsi; | ||||||||||||||||||||
| 152 | 0 | ▶ | while ($string_search_response =~ m{ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 153 | \<tr\s+class="search"\s*\> | ||||||||||||||||||||
| 154 | (.*?) | ||||||||||||||||||||
| 155 | \</tr | ||||||||||||||||||||
| 156 | }xmsgi) { | ||||||||||||||||||||
| 157 | 0 | my $row_raw = $1; | |||||||||||||||||||
| 158 | 0 | $row_raw =~ m{ | |||||||||||||||||||
| 159 | <td>(.*?)</td>\s* # map link | ||||||||||||||||||||
| 160 | <td>(.*?)</td>\s* # netid | ||||||||||||||||||||
| 161 | <td>(.*?)</td>\s* # ssid | ||||||||||||||||||||
| 162 | <td>(.*?)</td>\s* # comment | ||||||||||||||||||||
| 163 | <td>(.*?)</td>\s* # name | ||||||||||||||||||||
| 164 | <td>(.*?)</td>\s* # type | ||||||||||||||||||||
| 165 | <td>(.*?)</td>\s* # freenet | ||||||||||||||||||||
| 166 | <td>(.*?)</td>\s* # paynet | ||||||||||||||||||||
| 167 | <td>(.*?)</td>\s* # firsttime | ||||||||||||||||||||
| 168 | <td>(.*?)</td>\s* # lasttime | ||||||||||||||||||||
| 169 | <td>(.*?)</td>\s* # flags | ||||||||||||||||||||
| 170 | <td>(.*?)</td>\s* # wep | ||||||||||||||||||||
| 171 | <td>(.*?)</td>\s* # trilat | ||||||||||||||||||||
| 172 | <td>(.*?)</td>\s* # trilong | ||||||||||||||||||||
| 173 | <td>(.*?)</td>\s* # dhcp | ||||||||||||||||||||
| 174 | <td>(.*?)</td>\s* # lastupdt | ||||||||||||||||||||
| 175 | <td>(.*?)</td>\s* # channel | ||||||||||||||||||||
| 176 | <td>(.*?)</td>\s* # active | ||||||||||||||||||||
| 177 | <td>(.*?)</td>\s* # bcninterval | ||||||||||||||||||||
| 178 | <td>(.*?)</td>\s* # qos | ||||||||||||||||||||
| 179 | }xmsgi; | ||||||||||||||||||||
| 180 | 0 | push @records, { | |||||||||||||||||||
| 181 | netid => $2, | ||||||||||||||||||||
| 182 | ssid => $3, | ||||||||||||||||||||
| 183 | comment => $4, | ||||||||||||||||||||
| 184 | name => $5, | ||||||||||||||||||||
| 185 | type => $6, | ||||||||||||||||||||
| 186 | freenet => $7, | ||||||||||||||||||||
| 187 | paynet => $8, | ||||||||||||||||||||
| 188 | firsttime => $9, | ||||||||||||||||||||
| 189 | lasttime => $10, | ||||||||||||||||||||
| 190 | flags => $11, | ||||||||||||||||||||
| 191 | wep => $12, | ||||||||||||||||||||
| 192 | trilat => $13, | ||||||||||||||||||||
| 193 | trilong => $14, | ||||||||||||||||||||
| 194 | dhcp => $15, | ||||||||||||||||||||
| 195 | lastupdt => $16, | ||||||||||||||||||||
| 196 | channel => $17, | ||||||||||||||||||||
| 197 | active => $18, | ||||||||||||||||||||
| 198 | bcninterval => $19, | ||||||||||||||||||||
| 199 | qos => $20, | ||||||||||||||||||||
| 200 | userfound => $21, | ||||||||||||||||||||
| 201 | }; | ||||||||||||||||||||
| 202 | } | ||||||||||||||||||||
| 203 | 0 | return \@records; | |||||||||||||||||||
| 204 | } | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | # purpose : query wigle, trying to keep this simple | ||||||||||||||||||||
| 207 | # usage : args are optional, just provided for informational purposes | ||||||||||||||||||||
| 208 | # comments : returns an HTTP::Response object | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 0 | ▶ | sub query_raw { | ||||||||||||||||||
|
Subroutine
query_raw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 211 | 0 | my $self = shift; | |||||||||||||||||||
| 212 | 0 | my %args = @_; | |||||||||||||||||||
| 213 | 0 | return $self->post($url_query_base, \%args); | |||||||||||||||||||
| 214 | } | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 1 | 1; | |||||||||||||||||||
| 217 | __END__ | ||||||||||||||||||||