[Web4lib] IP address changes

Cloutman, David DCloutman at co.marin.ca.us
Fri Dec 7 13:52:50 EST 2007


You could probably set up an automated system fairly inexpensively that
would email you periodically when your address changed. I would
recommend purchasing a small web hosting account outside of your network
that supports your favorite scripting language, which in my case is PHP.
You then place a script on the external server that simply returns the
IP address of the requesting client. Your script would look something
like this:

<?php
// getIP.php
header('Content-Type text/plain);
echo $_SERVER['REMOTE_ADDR'];

// End



That's it on the server side. Because we are sending plain text, I have
left out the end delimeter intentionally. It is not needed for this
script to function as we are sending custom headers. You could write a
similar script in any web scripting language. You could also find a
friendly library that could host this script for you.

Now, here's the tricky part. Inside your network, set up your favorite
scripting language on a client computer where the public cannot access
it. I would use PHP. You don't need to set up anything like a web server
or database, just the scripting language. Just make sure that the
language and network are configured in such a way that you can send a
mail to your mail server. Also, if you're using PHP, make sure that the
CURL extension is installed and enabled.

Once you've done that you need to place a script like this on the client
computer:

<?php
// testIP.php

// Find out your current IP from the remote server
$ch = curl_init('http://your-remote-url/getIP.php');
// Without this next line, data will be passed to the standard output
instead of being 
// returned by curl_exe().	
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$remoteAddr = curl_exec($ch);



// Pull the current IP out of a file named currentIP.txt and test to see
if it is identical to your
// result from the remote server. If there is no file, or the remote IP
is different from the contents
// of the file, the file is overwritten.
if (!($currentAddr = file_get_contents('currentIP.txt')) || $currentAddr
!= $remoteAddr) {
	file_put_contents('currentIP.txt', $remoteAddr);
	mail('yourusername at bplnj.org', 'YOUR IP ADDRESS HAS BEEN
RESET!', "Your IP address has been reset. Your new IP is:
$remoteAddr\n\nPlease contact the database vendors to inform them of the
change.");
}

// End


There are probably bugs in this script (which I haven't tested), but the
basic concept is sound. Each time it runs, it checks the remote IP
against the current IP which is stored in a text file in the same
directory as script. If they match, it stops silently. If they don't
match, or if the file doesn't exist, the script will mail your. The
script will mail you the first time it runs, unless you create the file
with the correct IP. This is fine, because it will let you know the mail
function is working, and it will write the correct information to the
file automatically. 

The last step is to set your computer to run this script automatically
on a regular basis. Every 10 minutes would be good. How you do this is
dependent on your client computer's operating system. Just keep in mind
that the client machine will have to run continously during operating
hours, at a minimum. Ideally, you should have it up 24 / 7. That way,
you will have an email within 10 minutes of the IP change alerting you,
and you never have to remember to manually check it yourself.

Of course this isn't an optimal solution, and I can't see you changing
your IP address with all your vendors every few day indefinitely, but
perhaps if you only have one or two vendors, it isn't a big deal.
Regardless, until you have a static IP, this McGyvered solution should
work.

Good luck,

- David

---
David Cloutman <dcloutman at co.marin.ca.us>
Electronic Services Librarian
Marin County Free Library 

-----Original Message-----
From: web4lib-bounces at webjunction.org
[mailto:web4lib-bounces at webjunction.org] On Behalf Of L Cohn
Sent: Friday, December 07, 2007 9:29 AM
To: web4lib at webjunction.org
Subject: [Web4lib] IP address changes



I was told by the man who fixes our computers that we have a free
Comcast line and so the IP address of our library computers will change
every so often.  His answer to my next question was no, but I"m hoping
someone out there might have an idea for me.  

Instead of trying to log in to our online databases from inside the
library and finding out after the fact that our IP addresses have
changed, I was wondering if there was any way for me to be notified
automatically when our IP addresses have changed or are about to change.
Any ideas?

Thanks, 
Lisa

------------------------------------
Lisa Cohn, ILL, WebMaster,  Reference
Bloomfield Public Library,  bplnj.org
90 Broad Street, Bloomfield, NJ 07003
  (973-566-6200x217, lcohn at bplnj.org
------------------------------------
 
_______________________________________________
Web4lib mailing list
Web4lib at webjunction.org
http://lists.webjunction.org/web4lib/

Email Disclaimer: http://www.co.marin.ca.us/nav/misc/EmailDisclaimer.cfm



More information about the Web4lib mailing list