Newbie Question: Retreive and e-mail current IP with AppleSc

Hi,

I am just getting into AppleScript and what I want to know is:

Is it possible to write an AppleScrpt that will retrieve my current public IP address, then mail that address to a designated e-mail box?

I don’t really want to know HOW to do it since I am going to use this as a learning project. What I want to know is if this is in fact feasible, or would I just be pissing into the wind by attempting this.

thanks much in advance!

Tony

It should be a easy task. To get your public IP address, you can try several ways through the “do shell script” command.
To send a mail… AppleScript is your tool! (you can take full control over any scriptable app, such as Apple’s “Mail”, or Eudora, Entourage, Outlook, PowerMail, etc.; including again “do shell script” if you configure your OS’s built-in “sendmail”…

Here’s how you can get the current IP address

do shell script ("/sbin/ifconfig en0 | head -3 | grep 'inet ' | cut -d' ' -f 2")

This can be a way, or perhaps not… This will return my IP address, assigned by a DHCP server in a router… In this case, I need access to the router to retrieve this info…

True. Well, there are two ways to do this. Write some code (probably using the command-line utility ‘curl’) that accesses the router’s config web-page, and read out what the address is. Or, write some code that goes to a site like http://www.whatismyipaddress.com and reads out from THAT what the address is. The former doesn’t depend on someone else’s website sticking around. :slight_smile: Then again, the latter does not depend on one particular router’s admin web page format.

So, you’ll need to decide if this is only going to run on YOUR machine, or if it needs to have all kinds of options and backup method to run anywhere. If the latter, the task will be very difficult, since the whatismyipaddress.com website may change their format, making your reading code outdated.

Good luck! :slight_smile:

An easier way:

Write an applescript that launches an app which reports your IP to you:

DropIT - posts your IP to an FTP site of your choice as html code. Basically you have a webpage with your IP.

IP Reporter - This is more powerful (but I think it has some minor bugs). With this app you can have it check for either your LAN address or your WAN addres (via a site as mentioned above). It then sends the info to an FTP server (as DropIT) or you can have it emailed to you.

Why not set up IR Reporter to send you the IP as you need and just write an AS to launch IP Reporter?? Thats how I do it…

ewww.

do shell script "ifconfig en0 | awk '/inet / {print $2}'"

adjust en0/en1 as appropriate.