#!/usr/bin/perl # # getwebcaminage.pl # $Id: getwebcamimage.pl 102 2009-06-01 01:35:19Z rdk $ # # rdk@krupczak.org # get webcam image from TrendNET TV-IP110W # # COPYRIGHT 2006 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; my $ua; my $result; my $verbose = 0; my $help = 0; my $webcam = ""; my $outfilename = ""; # webcam passed in on arg line should include :port # set your username/password here for accessing the image # from the TV-IP110W; dont use your admin username/password my $username = "guest"; my $password = "guest"; $result = GetOptions( "help" => \$help, "verbose" => \$verbose, "webcam=s" => \$webcam, "out=s" => \$outfilename ); if ($help == 1 || $webcam eq "" || $outfilename eq "") { print "getwebcamimage.pl: --verbose --webcam hostname/ipaddr --out filename\n"; exit 0; } if ($username eq "admin") { print "Really, dont use the 'admin' user; create a guest user\n"; exit 0; } if ($webcam !~ /:/) { print "You need to specify a port number\n"; exit 0; } # construct the url my $url = "http://$webcam/cgi/jpg/image.cgi"; if ($verbose) { print "Fetching image from '$webcam' with '$url'\n"; } # 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; } exit -1;