bdgenz has asked for the wisdom of the Perl Monks concerning the following question:

Here's what I've got...
A web based only DNS update tool at the service provider.

The Solution so far...

use strict; use LWP; use LWP::Simple; use HTTP::Request::Common; use HTTP::Cookies; use HTML::Form;

What I think I'd like to do...

Any ideas?
I can post the script if needed.

TIA
BDGenZ

Edit by BazB: add formatting/code tags.

Replies are listed 'Best First'.
Re: Automated DNS Update Solution Needed
by Joost (Canon) on Dec 20, 2004 at 20:57 UTC
    Wow. That's a big paragraph, and I've only got a slight clue what you're actually asking.

    Nevertheless, you can probably remove all references to LWP, HTTP::Request, HTTP::Cookies and HTML::Form from your code and replace them with WWW::Mechanize, which should give you a much cleaner interface to the web-based tool.

    As for the rest of your question: what is your question? :-)

    Updated because reformatting made the question slightly clearer

    I stand by my recommendation of WWW::Mechanize, as it wil almost certainly make your code a lot simpler. The only thing it doesn't do (as far as I know) is give you the value of a filled in textarea field. HTML::Form should be able to do that for you:

    $form = HTML::Form->parse($html, $base_uri); $value = $form->value( $name );
    You can then parse $value and use the set_field() method of WWW::Mechanize to set the field value to the new value.

    If you want more information, you're going to have to go into more detail: what's the code of your script, what's the code of the html page you want to parse. and what do you want to submit back to the router.

    Most of us regular monks are glad to help, but we can't read your mind :-)

      The only thing it doesn't do (as far as I know) is give you the value of a filled in textarea field.
      Sure it does, demonstration (note q=test)
      C:\> perl -MWWW::Mechanize::Shell -e shell
      Module File::Modified not found. Automatic reloading disabled.
      >get http://www.google.com/search?hl=en&num=100&ie=UTF-8&oe=UTF-8&q=test&btnG=Google+Search
      Retrieving http://www.google.com/search?hl=en&num=100&ie=UTF-8&oe=UTF-8&q=test&btnG=Google+Search(200)
      http://www.google.com/search?hl=en&num=100&ie=UTF-8&oe=UTF-8&q=test&btnG=Google+Search>
      http://www.google.com/search?hl=en&num=100&ie=UTF-8&oe=UTF-8&q=test&btnG=Google+Search>forms
      Form [1]
      GET http://www.google.com/search [gs]
       num=100                        (hidden readonly)
       hl=en                          (hidden readonly)
       lr=                            (hidden readonly)
       q=test                         (text)
       btnG=Search                    (submit)
      Form [2]
      GET http://www.google.com/search
       q=test                         (text)
       btnG=Search                    (submit)
       num=100                        (hidden readonly)
       hl=en                          (hidden readonly)
       lr=                            (hidden readonly)
      http://www.google.com/search?hl=en&num=100&ie=UTF-8&oe=UTF-8&q=test&btnG=Google+Search>

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        That's an <input type="text" name="q">, not a <textarea name="q"></textarea>, on googles homepage, right?

        -Any sufficiently advanced technology is
        indistinguishable from doubletalk.

        My Biz

      Need to learn how to login too!
      BTW, I'll give WWW::Mechanize a try when I get a chance.
      Thanks again.
Re: Automated DNS Update Solution Needed
by Anonymous Monk on Dec 23, 2004 at 10:50 UTC
    Cool thanks all. Here's a snippet of what I ended up with...
    ## get the edit_dns page dump the current contents of the
    form to a file
    my $name = 'form_zone';

    my $response = $ua->get(EDIT_DNS);
    my $form = HTML::Form->parse($response->content,EDIT_DNS);
    my $value = $form->value( $name );
    ## check the contents of the dns text area
    #print $value;
    ## make a backup of the content
    open BACKUP, "> dns.backup.txt";
    print BACKUP $value;
    close BACKUP;
    ## this is the file we muck with
    open DNS, "> dns.txt";
    print DNS $value;
    close DNS;