|
No
static IP address? No problem! Al Williams shows you how,
with scripting, you need never be out of touch
When
I first got started in this business, computing was a lot
less accessible than it is now. I remember driving 60 miles
to reach the closest computer store. Nowadays, of course,
you can buy computers almost anywhere.
Networking has seen a similar transformation. There was a
time when getting connected was an arcane art; in 1969 it
was a big deal that a computer at the University of California,
Los Angeles had a connection to one at SRI International in
Menlo Park. Today, there is a high-speed fibre optic network
running through my backyard (literally-they all but dug up
my fence to put it in), and you can buy broadband network
hardware at any office supply store.
However, theres usually a catch: Broadband providers
frequently dont offer static IP addresses. Some services
(notably DSL) connect using PPP over Ethernet, which routinely
reassigns your network address. My cable modem, on the other
hand, uses DHCP to obtain a dynamic address. Some providers
will offer you a static IP for an additional fee. In other
cases, there is no way to get the provider to assign you a
permanent address at all.
Why should you care about having a static IP address? If youre
only surfing the Web, you probably shouldnt. However,
if you plan to use your broadband connection to collect remote
data, accept videoconference calls, or host a server, then
youll want some way for people on the Internet to find
you.
Redirection made easy
The domain name service (DNS) was created to make it easier
to locate machines on the network. Yet, there are a variety
of problems with using DNS to solve the problem of dynamic
IP addresses. First, you need to have the authority to create
and modify DNS entries. Second, it takes time for DNS records
to propagate through the system after each update.
Several services map a third-level domain name to an IP address
that you choose, including dynip.com, dyndns.org, and dns2go.com.
These generally provide client software that automatically
notifies their servers when your IP address changes. But if
you already have at least one static IP somewhere on the public
network, another solution is to create your own system.
Using a variety of Web scripting languages, you could build
a page that automatically learns a remote computers
IP address. Armed with that information, the page could redirect
Web visitors from your static IP address to the dynamic one.
Updating the record of your dynamic address would be trivial
as well. Although many IP redirection services use special
software for that purpose, youd just need to make a
Web request. After all, each request your Web browser makes
has your IP address bundled inside of it.
Making the connection
Of course, you dont want every request to reset your
IP address, just the ones from a browser running on your own
dynamic IP. To avoid chaos, youll need to make a secret
page, use password protection, or build in a magic phrase
that prevents casual browsers from changing your IP address.
Youll also need someplace global to store the IP address,
so that you can use it to handle other requests. With ASP,
the Application object is perfect for this purpose. You can
use this collection to store anything you like, and that data
will apply to all sessions. Because all sessions share the
one object, however, its important to lock the collection
before changing it.
Other issues
Any language that can examine the server variables and store
things in a globally-accessible location could perform the
same trick. JSP certainly meets these criteria. It has objects
named application and request, even though they arent
exactly the same as their ASP equivalents. However, the objects
perform the same tasks, just in slightly different ways.
This isnt the case with PHP, which has no persistent
storage like ASPs Application object. If you wanted
to write the same sort of program in PHP, youd have
to devise your own replacement for the Application object.
For example, you might store the IP address in a database,
shared memory, or even a file.
A problem with this scheme is that the Web clients must always
go through the script to find the correct remote IP. You could
put surrogate pages in place, such that each remote page has
a corresponding script on the static host. But this is far
from ideal, as it requires you to maintain duplicate pages.
Another possibility would be to change the 404 error page
into a script that redirects the user to the dynamic address.
This lets the dynamic server handle any pages that the static
host declines.
More IP address tricks
You might be tempted to use IP addresses as a way to uniquely
identify clients. This is a bad idea, as clients behind a
Network Address Translation (NAT) router will all appear to
use the same IP address. Nevertheless, in some cases, it can
be useful. For example, DSL Reports uses this method to prevent
a single IP address from running more than a certain number
of tests per hour.
Another use for tracking IP addresses is when you only want
to allow requests from certain IP addresses (or ranges of
IP addresses). For example, you could easily gain more security
in the dyn.asp script (Listing 1) by validating that the IP
address the client submits is from a network you expect.
You can easily do this by using the split command in VBScript.
Usually you think of split as a way to break words out of
a string, because the default separator is white space. However,
you can tell the command to use any string you like to tokenise
the string.
If you wish, you could change the target of the redirect to
include a different port number. Many broadband providers
have blocked port 80, so this is often useful.
Signing out
The only remaining problem is what to do when the remote host
is offline. Ideally, youd shut down the remote host
in an orderly fashion, so it has a chance to set the static
hosts global variable to an empty string. This causes
the static host to report that the remote host is offline.
You cant always depend on an orderly shutdown, though.
A power failure or a network interruption can take the remote
host offline or change its IP address. The remote host can
periodically set its IP using a custom program or an operating
system facility like cron or Task Scheduler. But this still
doesnt help in cases where the remote computer is completely
offline.
Other ideas
The scripts presented here act like traffic cops. They handle
requests by delegating to the remote host. This same idea
can work in other situations as well. For example, consider
a Web server that serves documents hosted on other Web servers.
The users see a central server, but the content comes from
a variety of different servers. Of course, youd have
to use some method to determine which requests go to which
servers.
This same strategy could also lend itself to a simple load-balancing
scheme. Using whatever algorithm you like, you can direct
individual requests to a different server. When using this
method, youd want to avoid storing persistent data in
cookies, for example, because a future visit might direct
the user to an alternate server.
With broadband likely to be installed in 41 percent of U.S.
homes by 2006, many things will become feasible that werent
practical in the past. Sure, the broadband business has had
some setbacks, but new, capital-intensive ventures often make
false starts. The real question now is what will you do with
a network thats everywhere?
www.webtechniques.com
|