|
| | |||||||
| Apple Macintosh Hardware Discuss the Apple Macintosh Hardware |
| | LinkBack | Thread Tools |
| |||
| Getting page by http from Linksys router My Linksys router (BEFSR41) connects to my DSL modem. My ISP provides a "dynamic" IP. Sometimes I want to know that IP (or want a script to know, actually). I use: lynx -auth=user:pass -dump http://192.168.1.1/Status_Router.htm and pipe that to sed to extract the IP from the one line (of 69) that contains it. I wonder whether there is resource-cheaper way to get the page from the router than firing up lynx every time. Be nice, too, if there were a way to get just the one line. I'm on a G5 running OSX, but this is really a bash/unix question, I guess. TIA & Cheers, N. -- |
| |||
| Re: Getting page by http from Linksys router In article <91bkm2-kh6.ln1@news.amhuinnsuidhe.net>, Nollaig MacKenzie <nollaig@amhuinnDELETEsuidheCAPS.net> wrote: > My Linksys router (BEFSR41) connects to my DSL modem. > My ISP provides a "dynamic" IP. Sometimes I want to > know that IP (or want a script to know, actually). > I use: > > lynx -auth=user:pass -dump http://192.168.1.1/Status_Router.htm > > and pipe that to sed to extract the IP from the one > line (of 69) that contains it. > > I wonder whether there is resource-cheaper way to get > the page from the router than firing up lynx every time. > Be nice, too, if there were a way to get just the one line. > > I'm on a G5 running OSX, but this is really a bash/unix > question, I guess. > > TIA & Cheers, N. > > -- Here is what I use: curl -s http://www.WhatIsMyIP.com | awk ' match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { print substr($0,RSTART,RLENGTH) exit } ' Or to capture that in a variable: IP=$(curl -s http://www.WhatIsMyIP.com | awk ' match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { print substr($0,RSTART,RLENGTH) exit } ') echo $IP But it is still a invoking a script that invokes command. In this case I use curl instead of lynx. I also use whatismyip.com Bob Harris |
| |||
| Re: Getting page by http from Linksys router On 2005.05.28 01:15:36, the amazing <nospam.News.Bob@remove.Smith-Harris.us> declared: > In article <91bkm2-kh6.ln1@news.amhuinnsuidhe.net>, > Nollaig MacKenzie <nollaig@amhuinnDELETEsuidheCAPS.net> wrote: > >> My Linksys router (BEFSR41) connects to my DSL modem. >> My ISP provides a "dynamic" IP. Sometimes I want to >> know that IP (or want a script to know, actually). >> I use: >> >> lynx -auth=user:pass -dump http://192.168.1.1/Status_Router.htm >> >> and pipe that to sed to extract the IP from the one >> line (of 69) that contains it. >> >> I wonder whether there is resource-cheaper way to get >> the page from the router than firing up lynx every time. >> Be nice, too, if there were a way to get just the one line. >> >> I'm on a G5 running OSX, but this is really a bash/unix >> question, I guess. >> >> TIA & Cheers, N. >> >> -- > > Here is what I use: > > curl -s http://www.WhatIsMyIP.com | awk ' > match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { > print substr($0,RSTART,RLENGTH) > exit > } > ' > > Or to capture that in a variable: > > IP=$(curl -s http://www.WhatIsMyIP.com | awk ' > match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { > print substr($0,RSTART,RLENGTH) > exit > } > ') > echo $IP > > But it is still a invoking a script that invokes command. In this case > I use curl instead of lynx. I also use whatismyip.com > > Bob Harris Thanks! Curl is what I wanted; it's a tenth the size of lynx, so using it should be significantly faster. Curl has a "--range <N-M>" option (retrieve only bytes N to M of the document), which would have been useful, but my router doesn't seem to support such requests. My knowledge of awk is very limited, so I'll stick with sed for now to extract the IP from the retrieved document. Cheers, N. -- |
| |||
| Re: Getting page by http from Linksys router In article <91bkm2-kh6.ln1@news.amhuinnsuidhe.net>, Nollaig MacKenzie <nollaig@amhuinnDELETEsuidheCAPS.net> wrote: > My Linksys router (BEFSR41) connects to my DSL modem. > My ISP provides a "dynamic" IP. Sometimes I want to > know that IP (or want a script to know, actually). > I use: > > lynx -auth=user:pass -dump http://192.168.1.1/Status_Router.htm > > and pipe that to sed to extract the IP from the one > line (of 69) that contains it. > > I wonder whether there is resource-cheaper way to get > the page from the router than firing up lynx every time. > Be nice, too, if there were a way to get just the one line. > > I'm on a G5 running OSX, but this is really a bash/unix > question, I guess. See the man page for ifconfig |
| |||
| Re: Getting page by http from Linksys router In article <7trom2-t4g.ln1@news.amhuinnsuidhe.net>, Nollaig MacKenzie <nollaig@amhuinnDELETEsuidheCAPS.net> wrote: > On 2005.05.28 01:15:36, > the amazing <nospam.News.Bob@remove.Smith-Harris.us> declared: > > > In article <91bkm2-kh6.ln1@news.amhuinnsuidhe.net>, > > Nollaig MacKenzie <nollaig@amhuinnDELETEsuidheCAPS.net> wrote: > > > >> My Linksys router (BEFSR41) connects to my DSL modem. > >> My ISP provides a "dynamic" IP. Sometimes I want to > >> know that IP (or want a script to know, actually). > >> I use: > >> > >> lynx -auth=user:pass -dump http://192.168.1.1/Status_Router.htm > >> > >> and pipe that to sed to extract the IP from the one > >> line (of 69) that contains it. > >> > >> I wonder whether there is resource-cheaper way to get > >> the page from the router than firing up lynx every time. > >> Be nice, too, if there were a way to get just the one line. > >> > >> I'm on a G5 running OSX, but this is really a bash/unix > >> question, I guess. > >> > >> TIA & Cheers, N. > >> > >> -- > > > > Here is what I use: > > > > curl -s http://www.WhatIsMyIP.com | awk ' > > match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { > > print substr($0,RSTART,RLENGTH) > > exit > > } > > ' > > > > Or to capture that in a variable: > > > > IP=$(curl -s http://www.WhatIsMyIP.com | awk ' > > match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) { > > print substr($0,RSTART,RLENGTH) > > exit > > } > > ') > > echo $IP > > > > But it is still a invoking a script that invokes command. In this case > > I use curl instead of lynx. I also use whatismyip.com > > > > Bob Harris > > Thanks! Curl is what I wanted; it's a tenth the size > of lynx, so using it should be significantly faster. > Curl has a "--range <N-M>" option (retrieve only bytes > N to M of the document), which would have been useful, > but my router doesn't seem to support such requests. > > My knowledge of awk is very limited, so I'll stick > with sed for now to extract the IP from the retrieved > document. > > Cheers, N. > -- Awk, sed, perl, whatever works. If you are interested in awk, here is a very good introductory web page that is not too long but gives a surprisingly good explanation of awk: <http://h30097.www3.hp.com/docs/base_..._HTML/ARH9WBTE /WKXXXXXX.HTM> In this case, the awk is rather simple. The basic form of an awk script is multiple pattern_selection { action on lines matching pattern } entries. match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) is the pattern. It is just looking for any line that contains a string of the form n.n.n.n, so 123.456.7.89 would match the regular expression pattern of /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ The $0 is the awk variable that contains the current line being processed. I used match because it will pre-load a couple of awk variables with the location of the found string and its length, which is useful for the action phase of the pattern{action} pair. ... { print substr($0,RSTART,RLENGTH) exit } is the action if match finds something. print is obvious. The substr() is again working on the awk variable $0 which is the current line where we found the n.n.n.n pattern. RSTART and RLENGTH are pre-loaded by the match command. So I'm extracting the n.n.n.n pattern from the current line and printing it. Since I have found what I'm looking for, I exit the awk script and stop processing any additional lines from the curl output. Bob Harris |
| |||
| Re: Getting page by http from Linksys router On 2005.05.29 14:01:36, the amazing <srhi@comcast.net> declared: > In article <91bkm2-kh6.ln1@news.amhuinnsuidhe.net>, > Nollaig MacKenzie <nollaig@amhuinnDELETEsuidheCAPS.net> wrote: > >> My Linksys router (BEFSR41) connects to my DSL modem. >> My ISP provides a "dynamic" IP. Sometimes I want to >> know that IP (or want a script to know, actually). >> I use: >> >> lynx -auth=user:pass -dump http://192.168.1.1/Status_Router.htm >> >> and pipe that to sed to extract the IP from the one >> line (of 69) that contains it. >> >> I wonder whether there is resource-cheaper way to get >> the page from the router than firing up lynx every time. >> Be nice, too, if there were a way to get just the one line. >> >> I'm on a G5 running OSX, but this is really a bash/unix >> question, I guess. > > See the man page for ifconfig I believe that ifconfig will only show my machine's local network address, 192.168.1.<2-254>. What I need is the IP address my router has on the internet, 65.95.120.148 right now. -- |
| |||
| Re: Getting page by http from Linksys router On Mon, 30 May 2005 07:07:44 -0400, Nollaig MacKenzie <nollaig@amhuinnDELETEsuidheCAPS.net> wrote: > I believe that ifconfig will only show my machine's > local network address, 192.168.1.<2-254>. What I need > is the IP address my router has on the internet, > 65.95.120.148 right now. wget -q -O- http://www.whatismyip.com/ | grep 'Your IP' | awk '{print $5}' | head -1 (unwrap this ; it is a single line of commands) Greets, Robert -- /^"- '-(\__/)-' -"^\ '-.' oo '.-' Holy Jesus! What are these god**** animals?! `-..-' Finger rvdm@db.debian.org for my GPG key. |
| Bookmarks |
| Thread Tools | |
| |
| | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Router problems Linksys | giddyup | Windows XP | 7 | 06-30-2008 11:11 AM |
| Vista and Linksys Router | radink | Windows Vista | 2 | 04-24-2007 09:45 AM |
| Linksys Wireless Router | JPCostaSr | Windows Vista | 5 | 03-29-2007 10:00 AM |
| Linksys Router. Vista compatible? | martagaspar | Windows Vista | 7 | 02-19-2007 02:30 PM |
| Getting page by http from Linksys router | Nollaig MacKenzie | Apple Macintosh Hardware | 6 | 02-06-2007 06:09 PM |
| New To Technology Questions? | Do You Need Help with Your Computer or Device? | Do You Need Help with this site? |