I sent this message before, but since I have not seen it
I have unsubscribed and resubscribed under a new account, and am sending it
again!
Here's a script I cobbled together yesterday so that I can
experiment with a web server behind an ADSL modem with NAT.
Since it's been a year since I last looked at Rebol, I've
forgotten the niceties of this language and I would appreciate
suggestions on how to improve it. I would also like to know how
to trap the break signal so that I can update the web page status
before quitting.
Run from command line as
rebol -s dynamicip.r
REBOL [
Title: "Maintain webserver on dynamic IP address allocation behind ADSL
modem using NAT"
File: %dynamicip.r
Date: 20-Nov-1999
Author: "Graham Chiu"
Purpose: {
Maintains a web page which redirects users to a dynamic IP address
or a static web page.
Since we are behind NAT, we don't know what our IP address is, and
we have to go to an external
website that can tell us this. A simple PHP3 or SSI script can do this.
We are assuming here that this address will be written on that page
enclosed by a couple of
tags such as
<IPAddress>1234.5678.9012.1234</IPAddress>
so that our script can parse it out. We take this address and write it via
ftp to our own
static web page which can then direct users to our dynamic web site.
This should also work for running a web site on a dial up line - though in
that case, you shouldn't
need to use an external utility to determine what your IP address is.
Sample SSI script - http://www.compkarori.com/oracle.shtml
<html><body>
<IPAddress><!--#echo var="REMOTE_ADDR" --></IPAddress>
</body></html>
}
]
notOften: 00:05:00
nowFrequently: 00:00:30
awhile: notOften
defaultIP: http://www.somewhere.com
currentIP: http://www.somewhere.com
newIP: defaultIP
oracle: http://www.compkarori.com/oracle.shtml ; this page should actually
work
statusPage: ftp://userid:[EMAIL PROTECTED]/redirect.html
defaultText: join join "<html><body>My current web address is <a href="
defaultIP ">Static</a> </body></html>"
dynamicText-part1: "<html><body>My current address is <a href=http://"
dynamicText-part2: ">Dynamic</a></body><p></html>"
statusText: defaultText
ReadingIP: [
page: read Oracle
parse page [ thru <IPAddress> copy newIP to </IPAddress> ]
]
UpdateStatus: [
write statusPage statusText
]
ResetToOffline: [
currentIP: defaultIP statusText: defaultText awhile:
nowFrequently
]
SetToOnline: [
currentIP: newIP
statusText: join join dynamicText-part1 newIP dynamicText-part2
]
while [ true ] [
either error? try ReadingIP [
print join "Unable to determine current IP address - resetting to "
defaultIP
ResetToOffline
either error? try UpdateStatus [
print join "Unable to update status page at " now
][
print join join join "Updated status page with " defaultIP " at
" now
]
][
; read the IP address okay
awhile: notoften
either newIP == currentIP [
print join "No change as of " now
][
print join "IP address changed and is now " newIP
SetToOnline
either error? try updateStatus [
print join "Unable to update status page at " now
ResetToOffline
][
print join join join "Updated status page with new IP address of "
currentIP " at " now
]
]
]
wait awhile
]
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com