line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IP::Info; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$IP::Info::VERSION = '0.18'; |
4
|
|
|
|
|
|
|
$IP::Info::AUTHOR = 'cpan:MANWAR'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
IP::Info - Interface to IP geographic and network data. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.18 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
73306
|
use JSON; |
|
4
|
|
|
|
|
42545
|
|
|
4
|
|
|
|
|
18
|
|
17
|
4
|
|
|
4
|
|
2401
|
use Data::Dumper; |
|
4
|
|
|
|
|
26262
|
|
|
4
|
|
|
|
|
230
|
|
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
4
|
|
1461
|
use IP::Info::Response; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
153
|
|
20
|
4
|
|
|
4
|
|
1768
|
use IP::Info::Response::Network; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
138
|
|
21
|
4
|
|
|
4
|
|
1646
|
use IP::Info::Response::Location; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
109
|
|
22
|
4
|
|
|
4
|
|
1534
|
use IP::Info::UserAgent; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
126
|
|
23
|
4
|
|
|
4
|
|
23
|
use IP::Info::UserAgent::Exception; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
78
|
|
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
|
19
|
use Digest::MD5 qw(md5_hex); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
214
|
|
26
|
4
|
|
|
4
|
|
2022
|
use Data::Validate::IP qw(is_ipv4); |
|
4
|
|
|
|
|
126970
|
|
|
4
|
|
|
|
|
287
|
|
27
|
|
|
|
|
|
|
|
28
|
4
|
|
|
4
|
|
30
|
use Moo; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
33
|
|
29
|
4
|
|
|
4
|
|
1357
|
use namespace::clean; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
30
|
|
30
|
|
|
|
|
|
|
extends 'IP::Info::UserAgent'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'base_url' => (is => 'ro', default => sub { 'https://api.sec.neustar.biz/ipi/gpp/v1/ipinfo' }); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Neustar IP Intelligence RESTful API provides the geographic location and network |
37
|
|
|
|
|
|
|
data for any Internet Protocol address in the public address space. |
38
|
|
|
|
|
|
|
The information includes: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over 5 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item * Postal code, city, state, region, country, and continent |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item * Area code (US and Canada only) and time zone |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item * Longitude and latitude |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * DMA (Designated Market Area) and MSA (Metropolitan Statistical Area) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item * Network information, including type, speed, carrier, and registering |
51
|
|
|
|
|
|
|
organization |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=back |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
To obtain "Free Developer Trial" API key and the shared secret, register your application L. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The constructor requires the following parameters as listed below: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
+---------+----------+----------------------------------------+ |
62
|
|
|
|
|
|
|
| Key | Required | Description | |
63
|
|
|
|
|
|
|
+---------+----------+----------------------------------------+ |
64
|
|
|
|
|
|
|
| api_key | Yes | API Key given by Quova. | |
65
|
|
|
|
|
|
|
| secret | Yes | Allocated share secret given by Quova. | |
66
|
|
|
|
|
|
|
+---------+----------+----------------------------------------+ |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use strict; use warnings; |
69
|
|
|
|
|
|
|
use IP::Info; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $api_key = 'Your_API_Key'; |
72
|
|
|
|
|
|
|
my $secret = 'Your_shared_secret'; |
73
|
|
|
|
|
|
|
my $info = IP::Info->new({ api_key => $api_key, secret => $secret }); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 ip_address($ip_address) |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
If an IP address is specified in the correct format, then the call returns an |
80
|
|
|
|
|
|
|
object of type L object which can be queried further to look |
81
|
|
|
|
|
|
|
for specific information for that IP. In case it encounters any error it'll throw |
82
|
|
|
|
|
|
|
an exception. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 2 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item * dot-decimal e.g. 4.2.2.2 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item * decimal notation e.g. 67240450 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
use strict; use warnings; |
93
|
|
|
|
|
|
|
use IP::Info; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $api_key = 'Your_API_Key'; |
96
|
|
|
|
|
|
|
my $secret = 'Your_shared_secret'; |
97
|
|
|
|
|
|
|
my $info = IP::Info->new({ api_key => $api_key, secret => $secret }); |
98
|
|
|
|
|
|
|
my $response = $info->ip_address('4.2.2.2'); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
print "Carrier: ", $response->network->carrier , "\n"; |
101
|
|
|
|
|
|
|
print "Country: ", $response->location->country, "\n"; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub ip_address { |
106
|
3
|
|
|
3
|
1
|
1212
|
my ($self, $ip) = @_; |
107
|
|
|
|
|
|
|
|
108
|
3
|
100
|
|
|
|
14
|
die ("ERROR: Missing parameter IP Address.") unless defined $ip; |
109
|
2
|
50
|
|
|
|
9
|
die ("ERROR: Invalid IP Address [$ip].") unless is_ipv4($ip); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
my $url = sprintf("%s/%s?apikey=%s&sig=%s&format=json", $self->base_url(), $ip, $self->api_key, $self->_sig()); |
112
|
0
|
|
|
|
|
0
|
my $response = $self->get($url); |
113
|
0
|
|
|
|
|
0
|
my $content = from_json($response->{content}); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
return IP::Info::Response->new({ |
116
|
|
|
|
|
|
|
ip_address => $content->{ipinfo}->{ip_address}, |
117
|
|
|
|
|
|
|
ip_type => $content->{ipinfo}->{ip_type}, |
118
|
|
|
|
|
|
|
network => IP::Info::Response::Network->new($content->{ipinfo}->{Network}), |
119
|
|
|
|
|
|
|
location => IP::Info::Response::Location->new($content->{ipinfo}->{Location}) |
120
|
0
|
|
|
|
|
0
|
}); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 schema($file_name) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Saves the XML Schema Document in the given file (.xsd file).In case it encounters |
126
|
|
|
|
|
|
|
any error it will throw an exception. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
use strict; use warnings; |
129
|
|
|
|
|
|
|
use IP::Info; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $api_key = 'Your_API_Key'; |
132
|
|
|
|
|
|
|
my $secret = 'Your_shared_secret'; |
133
|
|
|
|
|
|
|
my $info = IP::Info->new({ api_key => $api_key, secret => $secret }); |
134
|
|
|
|
|
|
|
$info->schema('User_supplied_filename.xsd'); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub schema { |
139
|
1
|
|
|
1
|
1
|
81
|
my ($self, $file) = @_; |
140
|
|
|
|
|
|
|
|
141
|
1
|
50
|
|
|
|
10
|
die ("ERROR: Please supply the file name for the schema document.") unless defined $file; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $url = sprintf("%s/schema?apikey=%s&sig=%s", $self->base_url(), $self->api_key, $self->_sig()); |
144
|
0
|
|
|
|
|
|
my $response = $self->get($url); |
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
open(SCHEMA, ">$file") or die ("ERROR: Couldn't open file [$file] for writing: [$!]"); |
147
|
0
|
|
|
|
|
|
print SCHEMA $response->{content}; |
148
|
0
|
|
|
|
|
|
close(SCHEMA); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _sig { |
152
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $time = time; |
155
|
0
|
|
|
|
|
|
return md5_hex($self->api_key . $self->secret . $time); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Mohammad S Anwar, C<< >> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 REPOSITORY |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 BUGS |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Please report any bugs or feature requests to C or |
169
|
|
|
|
|
|
|
through the web interface at L. |
170
|
|
|
|
|
|
|
I will be notified and then you'll automatically be notified of progress on your |
171
|
|
|
|
|
|
|
bug as I make changes. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SUPPORT |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
perldoc IP::Info |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
You can also look for information at: |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
L |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * CPAN Ratings |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * Search CPAN |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=back |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Copyright (C) 2011 - 2016 Mohammad S Anwar. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
206
|
|
|
|
|
|
|
the terms of the the Artistic License (2.0). You may obtain a copy of the full |
207
|
|
|
|
|
|
|
license at: |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified Versions is |
212
|
|
|
|
|
|
|
governed by this Artistic License.By using, modifying or distributing the Package, |
213
|
|
|
|
|
|
|
you accept this license. Do not use, modify, or distribute the Package, if you do |
214
|
|
|
|
|
|
|
not accept this license. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made by someone |
217
|
|
|
|
|
|
|
other than you,you are nevertheless required to ensure that your Modified Version |
218
|
|
|
|
|
|
|
complies with the requirements of this license. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service mark, |
221
|
|
|
|
|
|
|
tradename, or logo of the Copyright Holder. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge patent license |
224
|
|
|
|
|
|
|
to make, have made, use, offer to sell, sell, import and otherwise transfer the |
225
|
|
|
|
|
|
|
Package with respect to any patent claims licensable by the Copyright Holder that |
226
|
|
|
|
|
|
|
are necessarily infringed by the Package. If you institute patent litigation |
227
|
|
|
|
|
|
|
(including a cross-claim or counterclaim) against any party alleging that the |
228
|
|
|
|
|
|
|
Package constitutes direct or contributory patent infringement,then this Artistic |
229
|
|
|
|
|
|
|
License to you shall terminate on the date that such litigation is filed. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND |
232
|
|
|
|
|
|
|
CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED |
233
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR |
234
|
|
|
|
|
|
|
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS |
235
|
|
|
|
|
|
|
REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, |
236
|
|
|
|
|
|
|
INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE |
237
|
|
|
|
|
|
|
OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
1; # End of IP::Info |