-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetwebcamimage.pl
337 lines (266 loc) · 8.55 KB
/
getwebcamimage.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/perl
#
# getwebcaminage.pl
# $Id: getwebcamimage.pl 194 2012-12-10 23:03:10Z rdk $
#
# rdk@krupczak.org
# get webcam image from TrendNET TV-IP110W
# add support for D-Link DCS-920
# add support for Axis Neteye 2120
# add support for TrendNETs that differ on case of authen realm
# add support for command-line username/password
# add support for Foscam snapshots
#
# COPYRIGHT 2010 KRUPCZAK.ORG, LLC.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
# For more information, visit:
# http://www.krupczak.org/
#
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use Getopt::Long;
use HTTP::Cookies;
use HTTP::Headers;
use Image::ExifTool qw(:Public);
use Image::Magick;
my $ua;
my $result;
my $verbose = 0;
my $help = 0;
my $webcam = "";
my $camtype = "";
my $outfilename = "";
my $username = "";
my $password = "";
my $fillcolor = "white";
# webcam passed in on arg line should include :port
$result = GetOptions(
"help" => \$help,
"verbose" => \$verbose,
"webcam=s" => \$webcam,
"camtype=s" => \$camtype,
"username=s" => \$username,
"password=s" => \$password,
"fill=s" => \$fillcolor,
"out=s" => \$outfilename
);
if ($help == 1 || $webcam eq "" || $outfilename eq "") {
print "getwebcamimage.pl: --verbose --camtype type --username username --password password --fill colorname --webcam hostname/ipaddr:port --out filename\n";
exit 0;
}
if ($webcam !~ /:/) {
print "You need to specify a port number\n";
exit 0;
}
SWITCH: {
if ($camtype =~ /trendnet/i) { getTrendNet(); }
if ($camtype =~ /dlink/i) { getDlink(); }
if ($camtype =~ /neteye/i) { getNeteye(); }
if ($camtype =~ /foscam/i) { getFoscam(); }
print "Unsupported webcam type $webcam; I know about 'trendnet' and 'dlink' 'neteye' and 'foscam'\n";
}
exit -1;
# ###########################################################
# foscam
sub getFoscam
{
# set your username/password here for accessing the image
if ($username eq "") {
$username = "guest";
}
if ($password eq "") {
$password = "guest";
}
# construct the url
my $url = "http://$username:$password\@$webcam/snapshot.cgi";
if ($verbose) {
print "Attempting to fetch image from '$webcam' with '$url'\n";
}
# create a user agent first
$ua = LWP::UserAgent->new;
$result = $ua->get($url);
if ($verbose) {
print "Response is "; print $result->status_line; print "\n";
}
if ($result->is_success) {
# print $result->decoded_content;
open(OUTFILE,">$outfilename");
print OUTFILE $result->decoded_content;
close OUTFILE;
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($outfilename,"FileModifyDate");
my $image = Image::Magick->new;
$image->Read($outfilename);
# print "Date/time is $$info{FileModifyDate}\n";
$image->Annotate(font=>'ariel.ttf', pointsize=>20,
# stroke=>'white',
# fill=>'clear',
# default fill is black
fill=>$fillcolor,
text=>$$info{FileModifyDate},
gravity=>'NorthEast');
$image->Write(filename=>$outfilename, compression=>'None');
exit 0;
}
# if that didnt work,
exit -1;
}
# ###########################################################
# trendnet
sub getTrendNet
{
# set your username/password here for accessing the image
# from the TV-IP110W; dont use your admin username/password
if ($username eq "") {
$username = "guest";
}
if ($password eq "") {
$password = "guest";
}
# my $username = "stewart";
# my $password = "slicer1";
# construct the url
my $url = "http://$webcam/cgi/jpg/image.cgi";
if ($verbose) {
print "Attempting to fetch image from '$webcam' with '$url'\n";
}
if ($username eq "admin") {
print "Really, dont use the 'admin' user; create a guest user\n";
exit 0;
}
# create a user agent first
$ua = LWP::UserAgent->new;
$ua->credentials("$webcam","Netcam","$username" => "$password");
$result = $ua->get($url);
if ($verbose) {
print "Response is "; print $result->status_line; print "\n";
}
if ($result->is_success) {
# print $result->decoded_content;
open(OUTFILE,">$outfilename");
print OUTFILE $result->decoded_content;
close OUTFILE;
exit 0;
}
else {
# retry with lowercase netcam
$ua->credentials("$webcam","netcam","$username" => "$password");
$result = $ua->get($url);
if ($verbose) {
print "Response is "; print $result->status_line; print "\n";
}
if ($result->is_success) {
# print $result->decoded_content;
open(OUTFILE,">$outfilename");
print OUTFILE $result->decoded_content;
close OUTFILE;
exit 0;
}
}
# if that didnt work,
exit -1;
}
# ###########################################################
# dlink dcs 920
# dlink does not place a date/timestamp in the image;
# we add it using various tools
sub getDlink
{
# set your username/password here for accessing the image
if ($username eq "") {
$username = "guest";
}
if ($password eq "") {
$password = "guest";
}
# construct the url
my $url = "http://$username:$password\@$webcam/image.jpg";
if ($verbose) {
print "Attempting to fetch image from '$webcam' with '$url'\n";
}
# create a user agent first
$ua = LWP::UserAgent->new;
# $ua->credentials("$webcam","blah","$username" => "$password");
$result = $ua->get($url);
if ($verbose) {
print "Response is "; print $result->status_line; print "\n";
}
if ($result->is_success) {
# print $result->decoded_content;
open(OUTFILE,">$outfilename");
print OUTFILE $result->decoded_content;
close OUTFILE;
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($outfilename,"FileModifyDate");
my $image = Image::Magick->new;
$image->Read($outfilename);
# print "Date/time is $$info{FileModifyDate}\n";
$image->Annotate(font=>'ariel.ttf', pointsize=>20,
# stroke=>'white',
# fill=>'clear',
# default fill is black
fill=>$fillcolor,
text=>$$info{FileModifyDate},
gravity=>'NorthEast');
$image->Write(filename=>$outfilename, compression=>'None');
exit 0;
}
# if that didnt work,
exit -1;
}
# ###########################################################
sub getNeteye
{
# set your username/password here for accessing the image
$username = "";
$password = "";
# construct the url
my $url = "http://$webcam/jpg/image.jpg";
# create a user agent first
$ua = LWP::UserAgent->new;
# $ua->credentials("$webcam","blah","$username" => "$password");
$result = $ua->get($url);
if ($verbose) {
print "Response is "; print $result->status_line; print "\n";
}
if ($result->is_success) {
# print $result->decoded_content;
open(OUTFILE,">$outfilename");
print OUTFILE $result->decoded_content;
close OUTFILE;
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($outfilename,"FileModifyDate");
my $image = Image::Magick->new;
$image->Read($outfilename);
# print "Date/time is $$info{FileModifyDate}\n";
$image->Annotate(font=>'ariel.ttf', pointsize=>20,
# stroke=>'white',
# fill=>'clear',
# default fill is black
fill=>$fillcolor,
text=>$$info{FileModifyDate},
gravity=>'NorthEast');
$image->Write(filename=>$outfilename, compression=>'None');
exit 0;
}
# if that didnt work,
exit -1;
}
# ###########################################################