From sheff at pobox.com Wed Oct 10 20:52:20 2001 From: sheff at pobox.com (Keith W. Sheffield) Date: Thu Aug 5 00:07:19 2004 Subject: [Memphis.pm] Re: [GOLUM] How to get Linksys routers WAN ip??? In-Reply-To: "Emory Smith"'s message of "Wed, 10 Oct 2001 19:43:07 -0500" References: Message-ID: >>>>> "Emory" == Emory Smith writes: > I have a Linksys router on RR and would like to have > my server (MDK8.1) poll it about 2-3 times a day and > get its WAN ip and send it to my work email. > I can get into the routers status page by browsing to > http://yada:password@192.168.1.1/Status.htm with > Mozilla or Netscape. (Username (yada) can be anything). > Lynx complains, ask questions and ultimately doesn't get in. > Is there another text based browser that might do this? > It would seem that I should be able to redirect the browser's > output to grep and mail the result. > Or, Brock might have some really eloquent method. (hint, hint) LWP is your friend. Like many things, there's more than one way to do it: very simple way: -------------------------- #!/usr/bin/perl use MIME::Lite::HTML; my $mailHTML = new MIME::Lite::HTML From => 'me@mymachine', To => 'my@atwork', Subject => 'Mail in HTML with images'; $MIMEmail = $mailHTML->parse('http://yada:password@192.168.1.1/Status.htm'); $MIMEmail->send; ------------------- That's assuming that it knows how to do the yada:password stuff and it will include any images in the email Here's the way I do it at work and it creates absolute links to images and other stuff if needed: -------------------------------- #!/usr/bin/perl -- # -*-Perl-*- use strict; use LWP::UserAgent ; use HTTP::Cookies; use HTML::TreeBuilder; use MIME::Lite; use URI::URL; use URI::Escape qw(uri_unescape); # id/password combo for getting into status page my $user_id = 'yada'; my $user_pw = 'password'; # if you need an id/password combo to get out of the proxy #my $proxy_id = ""; #my $proxy_pw = ""; my $from_addr = "me@mymachine"; my $to_addr = "me@work"; my $baseurl = "http://192.168.1.1"; my $url = "$baseurl/Status.htm"; # create a web user agent object my $ua = new LWP::UserAgent || die "$!"; #$ua->proxy(['http', 'ftp'] =>'http://myproxy:8080'); #$ua->no_proxy(qw(domain)); $ua->agent('Mozilla/4.03'); #In case you want cookies my $cookie_jar = HTTP::Cookies->new; # get a request object for sending the data file my $req = new HTTP::Request 'GET', $url; die "Error building request\n", unless($req); # set all the password stuff and make sure we can store cookies $req->authorization_basic($user_id, $user_pw); # uncomment if using a proxy that needs passwords #$req->proxy_authorization_basic($proxy_id, $proxy_pw); $cookie_jar->add_cookie_header($req); # get the results my $res = $ua->request($req); die "Error getting results from request\n" unless ($res); if ($res->is_success) { # we get a valid result back, so send email to anyone that cares. $cookie_jar->extract_cookies($res); print " ----- Cookies from $url ------\n"; print $cookie_jar->as_string; # parse the html my $html = new HTML::TreeBuilder; $html->parse($res->content); &xform_urls($html); # and make all the links/images absolute so we can # see them # now create the email object my $msg = new MIME::Lite From => $from_addr, To => $to_addr, Subject => "Status results", Type => 'multipart/mixed'; # include our response page attach $msg Type => 'text/html', Data => $html->as_HTML(undef, " "); # Send the mail and do the honorable thing to do if you fail. $msg->send || die "Error sending email!\n"; print "Mail sent!\n"; exit(0); } else { print $res->error_as_HTML() if ($res->is_error); print $res->status_line, "\n"; } exit(1); # # This function takes a parsed html tree or subtree and transforms any # relative urls or images to absolute ones so that the html can be viewed # in an html email client or on another web server # sub xform_urls { my $x = $_[0]; my $tag = lc $x->tag; $x->attr('href', uri_unescape(url($x->attr('href'),$baseurl )->abs)) if ($tag eq "a" && defined $x->attr('href')); $x->attr('src', uri_unescape(url($x->attr('src'),$baseurl )->abs)) if ($tag eq "img" && defined $x->attr('src')); foreach my $c ($x->content_list) { xform_urls($c) if ref $c; # ignore text nodes } } ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From alaricravenhall at hotmail.com Fri Oct 19 19:36:09 2001 From: alaricravenhall at hotmail.com (Alaric Ravenhall) Date: Thu Aug 5 00:07:19 2004 Subject: [Memphis.pm] smc barricade routerand dynamic dns script Message-ID: Hi mongers. I've run into an interesting problem I'm going to solve with Perl. I have a friend with an ethernet DSL modem and an SMC barricade router. He is running an apache webserver and has a dynamic DNS name - Hn.org. He wants to automatically update his DNS with his current IP every hour. No problem with Linux and cron, right? Well... he is behind the router and the hn.org Perl script grabs the ip address of his webserver, which is assigned via DHCP. So, heres's my plan: Write a Perl script that pulls the embedded web page from his router and regexes it for the external IP. Store that to a variable, and throw it up to HN.org in the required manner. Schedule it with cron, and BAM!(props to Emeril) issue solved! I will probably use LWP:user agent to pull the page from the router. Comments? Ravenhall _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ---------------------------------------------------------------------------- From philarete at mindspring.com Sat Oct 20 16:58:45 2001 From: philarete at mindspring.com (Brock Sides) Date: Thu Aug 5 00:07:19 2004 Subject: [Memphis.pm] smc barricade routerand dynamic dns script In-Reply-To: ; from alaricravenhall@hotmail.com on Fri, Oct 19, 2001 at 07:36:09PM -0500 References: Message-ID: <20011020165845.A6972@harmless.yellowsnow.org> * Alaric Ravenhall [011019 20:02]: > I've run into an interesting problem I'm going to solve with Perl. > I have a friend with an ethernet DSL modem and an SMC barricade router. He > is running an apache webserver and has a dynamic DNS name - Hn.org. > He wants to automatically update his DNS with his current IP every hour. No > problem with Linux and cron, right? Well... he is behind the router and the > hn.org Perl script grabs the ip address of his webserver, which is assigned > via DHCP. So, heres's my plan: > Write a Perl script that pulls the embedded web page from his router and > regexes it for the external IP. Store that to a variable, and throw it up to > HN.org in the required manner. Schedule it with cron, and BAM!(props to > Emeril) issue solved! > I will probably use LWP:user agent to pull the page from the router. > Comments? > Ravenhall Sounds like the kind of problem Perl was made to solve. How about posting your code to the list, so we can take a look at it, and either (a) learn something, or (b) offer suggestions. -- Brock Sides philarete@mindspring.com One OS to rule them all, one OS to find them, One OS to bring them all and in the darkness bind them, In the land of Redmond, where the shadows lie. ---------------------------------------------------------------------------- To unsubscribe, please send email to majordomo@pm.org with 'unsubscribe memphis-pm-list' in the body of the message. ----------------------------------------------------------------------------