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

From: Eben King (eben1@tampabay.rr.com)
Date: Sat Apr 01 2006 - 14:49:51 EST


On Sat, 1 Apr 2006, 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.

Gee, that sounds like what I had to do to embed my (dynamic) IP address in
an HTML page.

> My question is, what language should I investigate to accomplish this?

I'd use {k,ba,}sh, since that's what I know well.

> Is this able to be done with a bash script and command line utilities

Yeah, or if you can use CGI you can write your pseudo-HTML with meta tags,
and replace those tags at run time with your address. Makes the "extract
the IP address" part trivially easy, but then you have to write a CGI
script.

sed -n '/ [1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]* /s/^.*
\([1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\) .*$/\1/p' < file.html
> address

Just make sure the address is flanked by spaces in file.html .

> 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.

Heck, use what you know. First-time code is usually pretty bad.

-- 
"The Web brings people together because no matter what kind of a twisted
  sexual mutant you happen to be, you've got millions of pals out there.
  Type in 'Find people that have sex with goats that are on fire' and the
  computer will say, 'Specify type of goat.'" -- Rich Jeni
-----------------------------------------------------------------------
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:26:36 EDT