Re: [SLUG] script to parse and compare an IP address

From: Sick Twist (thesicktwist@hotmail.com)
Date: Sat Apr 01 2006 - 16:21:57 EST


>From: Paul M Foster <paulf@quillandmouse.com>
>Reply-To: slug@nks.net
>To: slug@nks.net
>Subject: Re: [SLUG] script to parse and compare an IP address
>Date: Sat, 01 Apr 2006 12:56:18 -0500
>
>Sick Twist wrote:
>
>>I am trying to write a script that parses an unknown IP address from a
>>page of HTML, compares the IP address to a file and overwrites the file if
>>the saved IP address is different. My question is, what language should I
>>investigate to accomplish this? Is this able to be done with a bash script
>>and command line utilities or is there another language like perl or
>>python that would be better suited for this task? C has always been my
>>game so I'm less familiar with the strengths and capabilities of some of
>>the other tools out there. Thanks in advance!
>>
>
>Let the language wars begin! ;-}
>
>If this is something that you could run from a web page, I'd suggest PHP.
>Its syntax is the most similar to C, of the languages you mentioned.
>
>I've written code in Perl, but I no longer do. Perl is hard to read, and
>has odd conventions for naming variables, depending on the type of the
>variable and the context. However, for doing regexp work, Perl has the
>simplest interface. It's built in to the language; completely integrated.
>
>Python is my choice for this kind of work. However, Python has some quirks,
>too. First, it has almost no end-of-line delimiters and requires strict
>indentation, a fact that causes jeers from its detractors. In addition, to
>do regexp work you must include a statement at the beginning of the file to
>pull in the regexp module; like an #include directive in C. The method of
>doing regexp work is more complicated than Perl. But the language is
>more... orthogonal?... than Perl. Perl's kinda down-and-dirty
>it'll-figure-out-what-you-mean. Python is more rigorous.
>Larry Wall (Perl creator) built Perl so that there many many ways to do the
>same thing, some quite counter-intuitive. Guido Van Rossum (Python's
>creator) wanted a language with the power of Perl, but with a more
>regular/orthogonal/rigorous syntax. Fortunately, both these languages don't
>require the same pre-declaration of variables that C does, and they do
>garbage collection that C can't.
>
>These scripting languages drive me crazy because their syntax for certain
>common tasks is just different enough from each other and C that you often
>make stupid mistakes while coding. (else if, elseif, elif, elsif...) This
>is one of the reasons I prefer PHP when I can use it-- it's close enough to
>C syntax that I seldom use the wrong keyword, and I still have to terminate
>lines with a semicolon (unlike Python).
>
>If this is a one-shot deal, you might just consider using grep/sed and
>bash. That's got to be easier than mastering the intricacies of a whole new
>language.
>
>Paul
>
>--
>Paul M. Foster

Yep, one-shot deal. Basically I want a script that will automatically log-in
to my router (via curl or wget) and download the status page. Then I want to
parse the page to obtain the router's external IP address and compare it
with one that was saved previously to determine if it has changed. If so,
the script should send me an e-mail with the current IP address. This is a
poor man's substitute for a static IP :)

Honestly not trying to start any language wars. I just didn't know what
would be most efficient for this sort of thing. Awk, sed, perl, python and
CLI utils all came to mind but I didn't want to start heading down a
dead-end street as I'm not intimately familiar with any of them.

-Jonathon

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:27:20 EDT