What do you need to do with it then? Is it so you can get to your server externally? If this is the case then you can always register a name with DynDNS (
http://www.dyndns.org) that will follow your IP around when it changes, or you could run something like
so you get emailed your IP address.
Just a few thoughts, I don't know how much sucess you will have trying to script a standard telnet package... you might be able to do something similar with Perl, but you'd have to write the telnet part of it yourself I believe...
good luck!
Jamie...