Here is another alternative that depends on hosts who's business resolves around managing dynamic IP rather that "public service" sites that may go away or change format.
1) Register your server at one of the many free dynamic dns services (e.g. no-ip.com) This will give you a DNS entry like xxx.no-ip.org.
2) Install the service's dynamic update tool (reports IP changes to service).
To get the IP address in a script, just do:
$external_ip = `dig +short xxx.no-ip.org`
Great for use in cron job to check if dynamic IP has changed and some configuration entries need to be changed.