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

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


>From: Eben King <eben1@tampabay.rr.com>
>Reply-To: slug@nks.net
>To: slug@nks.net
>Subject: Re: [SLUG] script to parse and compare an IP address
>Date: Sat, 1 Apr 2006 14:49:51 -0500 (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.

I don't need to create HTML, just pull an IP address out of it. Basically,
I have a string with an IP address in the middle and I need to write a
script that strips out just the IP address so that I can save it to a file.
I forgot about sed but will definitely read up on it.

-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:26 EDT