How can i keep track of my IP address.........

How can i keep track of my MacBookPro IP addresses for ethernet, Airport, PPP, IP over FireWire, and a 3rd party ethernet card (if i installed) and report to my mail address, the IP address automatically via OS X Mail once a day and i like it if it can send a report of the addresses anytime i wish. If an IP changes, it need automatically send to me a report of what has changed. It would really nice if it can also displays my “real” IP address if i m behind a firewall.

It would really very nice if i can see the code.

Best Regards,
macautomator@gmail.com

Hi skysurferfx,

Welcome to MacScripter! Please don’t post your question to multiple forum sections at once :wink:

To get information about your current IP configuration you could use the «ifconfig» command and parse the necessary information:


set ipinfo to do shell script "ifconfig"

Or you could use System Profiler:


set ipinfo to do shell script "system_profiler SPNetworkDataType"

That sounds like a nice script. Have you done any searching? What have you come up with so far?

I only found .app Ipenema. But i need to see code.

I use this for inside and outside:

set {Ext_IP, Int_IP} to {word 25, word 32} of (do shell script "curl checkip.dyndns.org;ipconfig getifaddr en0")

Error:

Interesting, Bruce – it runs perfectly on my dual-core G5, but gets the same failure on my MacBook Pro! I’ve used it for so long that I didn’t think to check on the laptop.

I don’t know if it helps but this is what I use to get my network information.

-- This gets your external IP address and the internal network IP and mac address for each active network interface

-- get external IP
set networkInfo to getExternalIP() as list

-- get internal IPs and mac addresses
repeat with i from 0 to 3
	getIPandMac(i)
	if result is not false then set end of networkInfo to result
end repeat

-- results
return networkInfo


(*===================== SUBROUTINES =======================*)
on getExternalIP()
	try
		set webResults to do shell script "curl [url=http://checkip.dyndns.org/]http://checkip.dyndns.org/"[/url]
		set text item delimiters to "Current IP Address: "
		set a to item 2 of (text items of webResults)
		set text item delimiters to "<"
		set externalIP to item 1 of (text items of a)
		set text item delimiters to ""
	on error
		set externalIP to "unknown"
	end try
	return externalIP
end getExternalIP

on getIPandMac(interfaceNumber)
	try
		set theResults to do shell script "/sbin/ifconfig en" & interfaceNumber
		set text item delimiters to "inet "
		set a to item 2 of (get text items of theResults)
		set text item delimiters to " netmask"
		set internalIP to item 1 of (get text items of a)
		set text item delimiters to "ether "
		set a to item 2 of (get text items of theResults)
		set text item delimiters to space & return
		set internalMac to item 1 of (get text items of a)
		set text item delimiters to ""
		return {interfaceNumber, internalIP, internalMac}
	on error
		return false
	end try
end getIPandMac

So once you get your information using the above script you need to work on the other parts of your project. For example here’s one way to accomplish your final goal.

  1. write the results to a text file
  2. run the script periodically and compare the results to the text file
  3. if they changed then write the new results to the text file
  4. if they changed then send yourself an email too
  5. you can use launchd to periodically run the script

All of the tools you need have been posted before on this site before. You can find code for reading/writing to files, sending emails, and even using launchd… so you just need to search for them and put it all together. I don’t think you’ll find anyone to write the whole script for you but you can ask questions as you go along. That’s how you learn.

Turns out that the failure is because my Laptop is wireless, so it’s not using en0, it’s using en1. The script below looks after that for me:

set Ext_IP to word 25 of (do shell script "curl checkip.dyndns.org")
try
	set Int_IP to (do shell script "ipconfig getifaddr en0")
on error -- box is not wired, try wireless
	set Int_IP to (do shell script "ipconfig getifaddr en1")
end try
{Ext_IP, Int_IP}

Hello, So I’m new to Apple Script well any code for that matter.So i have a ton of questions but right now I need something like this apple script to be up and working sooner than later.

I am using a Remote Login client from my iPhone which works great on Wifi and 3G. But I’m having a problem with the 3G side of things because my IP address changes.
I have AT&T Home Internet and I’m using there 2Wire Wifi/Router. I had a Apple Airport extreme base station between my iMac and 2wire router but took it out for right now. Anyways
One of my friends at the College is using a Script for his AT&T router which is the same as mine. But he has a website he uses to stream stuff from his servers at his house. (He is also one of the Admins in Network for the College) the script he is using is for Windows and its a .exe
So I’m trying to find something that will work for my needs.

I only want to use the VNC client from my iPhone to the Mac on any Network that has an internet connection without having the problem of my Dynamic IP changing the info on me when I need to help my parents do something they can’t figure out (Which is 99.999% of the time)

The way he has the .exe script working is, every time the IP changes it runs and uploads the changes to his server. That’s what he told me in a text a little bit ago.
I don’t have a Server and I don’t stream music or video from the mac to anyone.

Will the script you have written a few years ago work for what I need? If so is that all I need or will I need to change or add anything to it?

If anything needs to be added or changed I’m not sure if I will be able to do so since my Rubber boots are already full of water and I’m starting to sink in the mud that makes up the bottom of the river. In other words, I think I’m screwed unless someone might be kind enough to help me out.

Thank you everyone who answers and tries to throw a life line.

PS. I’ll go ahead and say it since my statement above pretty much does.
When I say “Unless someone might be kind enough to help me out” If you didn’t catch in my post I don’t have any background in Writing any Code and I know this script is probably way to much for someone as new to this as me but I really need this to work 100% of the time since I don’t live with them anymore and I can’t just run over every night when something goes wrong. I’m don’t need this to show my friends what I can do and how cool I am with my iPhone, but I needs this because my parents sometimes need help with simple task such as viewing a email with a attachment.
So when I asked for someone to help me out I’m really asking for a whole lot and really hopping someone will take the time to maybe write it or at least show me how to do so. I know that’s a lot to ask but I’m not sure what else I can do.
Thanks again

Yes, the scripts listed still work. They will get your external and internal ip addresses. Unfortunately this website is for people who want to learn applescript. The people on here are very good help but you always need to show that you’re willing to put in the effort yourself first. As such I doubt anyone will write the code for you because this would take lots of customization to set it up specifically for your use.

There is another way though and it’s fairly easy to do. You can sign up for a free dynamic ip account which would track the ip address for you. Then when you need to know the ip address you just login to your account with them and it shows your ip address. You basically just install an application on your computer and it automatically uploads your latest ip address to their website. There’s several sites that do this and it’s free. I’ve used this website for years: http://www.no-ip.com/.

So you have 3 choices.

  1. learn applescript and write the rest of the customized code yourself. I outlined the steps you could take to do this so you just have to work through it and ask for help when needed.

  2. try http://www.no-ip.com/. You could set this up on your parent’s computer.

  3. pay somebody to write the code. If you’d like to do this you can contact me offline through my website http://www.hamsoftengineering.com.

Good luck.

You can also get your IP from

set ipinfo to IPv4 address of (get system info)

that’s the internal IP address, you need the public IP address :wink:

Hey Dude,

I really liked the concept of what you where suggesting so i’ve just spent 20 mins on it. You’ve asked for:

1 - In the code posted Here
2 - Havn’t aded yet, however, if you put script in startup at moment, and check log to see if there is a differece
3 - Havn’t added yet - however, have the write a file in there
4 - do need this myself, unless you have a static IP cannot see the need for it - Most ISP’s are Dynamic - sure you can use an if / then / else to check and review change
5 - As mentioned in 2 - place in startup of mac in system preferences (after creating as an APP)

My Code:

set myLog1 to "$HOME/Desktop/IP_Log.log" -- creating a log
set theDate to (current date) as text -- setting the time and date

set Ext_IP to word 25 of (do shell script "curl checkip.dyndns.org")

try
	set Int_IP to (do shell script "ipconfig getifaddr en0")
	
	-- retreive the ip address and then return infomation with a cancel button
	
	display dialog "Your External IP Followed By Internal IP is: " & {Ext_IP} & return & {Int_IP} buttons {"Save IP Data", "Cancel"} default button 2 with title "iP Config Stats v1.0" with icon note

	if the button returned of the result is "Save IP Data" then --- save ip data creates the log file and saves / cancel kills it
		
		do shell script "echo " & return & "Your IP Data Was Checked on " & theDate & return & Ext_IP & return & Int_IP & ">>" & myLog1
		
end if

on error -- box is not wired, try wireless
	
	set Int_IP to (do shell script "ipconfig getifaddr en1")
	
	-- retreive the ip address and then return infomation with a cancel button
	
	display dialog "Your External IP Followed By Internal IP is: " & {Ext_IP} & return & {Int_IP} buttons {"Save IP Data", "Cancel"} default button 2 with title "iP Config Stats v1.0" with icon note
	
	if the button returned of the result is "Save IP Data" then --- save ip data creates the log file and saves / cancel kills it
		
		do shell script "echo " & return & "Your IP Data Was Checked on " & theDate & return & Ext_IP & return & Int_IP & ">>" & myLog1
		
	end if
end try

I don’t know if it can help anyone, but I use this script to upload my LAN & WAN IP. I keep it running with launchd.

property LOG_FILE : "~/Documents/IP Uploader Log.txt"
property IP_STORAGE : "~/Documents/IP.html"
property IP_SITE : "http://checkip.dyndns.org/"
property IDLE_RETURN_VALUE : 15 * minutes

property UPLOAD_PATH : "ftp://1.1.1.1/public/ip.html"
property USER_NAME : "" -- server username
property USER_PASS : "" -- server password

on idle
	-- GET WAN IP
	set wanIP to getWAN_IP()
	
	-- error
	if wanIP is missing value then
		logError(("Could not receive WAN IP address from " & quoted form of IP_SITE) as string)
		return IDLE_RETURN_VALUE
	end if
	
	-- GET LOCAL IP
	set localIP to getLocal_IP()
	
	-- error
	if localIP is missing value then
		logError("Could not receive LAN IP address")
		return IDLE_RETURN_VALUE
	end if
	
	-- WRITE TO FILE
	writeIP(wanIP, localIP)
	
	-- UPLOAD
	set uploadSuccess to uploadFile(stringByExpandingTildeInPath(IP_STORAGE), UPLOAD_PATH, USER_NAME, USER_PASS)
	if uploadSuccess is false then
		logError(("Failed to upload file to " & UPLOAD_PATH) as string)
		return IDLE_RETURN_VALUE
	end if
	
	return IDLE_RETURN_VALUE
end idle

(* ===== HANDLERS ===== *)
on writeIP(wanIP, localIP)
	set ipFile to stringByExpandingTildeInPath(IP_STORAGE)
	makeFile(ipFile, 1)
	
	try
		set ipFile to (HSFWithPOSIX(ipFile) as alias)
	on error
		return false
	end try
	
	set myData to ("<html><body>")
	
	-- data
	set myDate to do shell script "date '+%Y.%m.%d'"
	set myTime to time string of (current date)
	set myData to (myData & "IP on " & myDate & " <i>(" & myTime & ")</i>: <br /><br />") as string
	set myData to (myData & "WAN: " & wanIP & "<br />LAN: " & localIP) as string
	
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "."
	set lastLocal to text item -1 of localIP
	set AppleScript's text item delimiters to tid
	if (count (lastLocal as string)) is 1 then set lastLocal to ("0" & lastLocal) as string
	set myData to (myData & " <br /><i>(PORT: 80" & lastLocal & ")</i><br /><br />") as string
	
	set hyperlink to ("<a href=\"sftp://" & wanIP & ":80" & lastLocal & "\">sftp://" & wanIP & ":80" & lastLocal & "</a>") as string
	set myData to (myData & hyperlink & "</body></html>") as text
	
	-- write
	set OA to open for access ipFile with write permission
	try
		write myData to OA starting at 0 as text
		close access OA
	on error
		try
			close access OA
		end try
		logError(("Could not write IP to file (" & wanIP & ", " & localIP & ")") as string)
		return false
	end try
	
	return true
end writeIP

on getLocal_IP()
	set shellResult to do shell script "ifconfig en1"
	if shellResult contains "inactive" then set shellResult to do shell script "ifconfig en0"
	if shellResult contains "inactive" then return missing value
	
	set tid to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to "inet "
		set myIP to text item 2 of shellResult
		set AppleScript's text item delimiters to " netmask "
		set myIP to text item 1 of myIP
	on error
		set myIP to missing value
	end try
	
	set AppleScript's text item delimiters to tid
	return myIP
end getLocal_IP

on getWAN_IP()
	set siteSource to sourceOfWebPage(IP_SITE)
	
	-- on error
	if siteSource is missing value then return missing value
	
	-- GET IP
	set tid to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to "Current IP Address: "
		set myIP to text item 2 of siteSource
		set AppleScript's text item delimiters to "</"
		set myIP to text item 1 of myIP
		set AppleScript's text item delimiters to tid
	on error
		set myIP to missing value
	end try
	
	set AppleScript's text item delimiters to tid
	return myIP
end getWAN_IP

on logError(aString)
	set theFile to stringByExpandingTildeInPath(LOG_FILE)
	
	set myExists to false
	try
		get (info for (alias (HSFWithPOSIX(theFile))))
		set myExists to true
	end try
	
	-- make file
	if myExists is false then makeFile(theFile, 1)
	try
		set theFile to (alias (HSFWithPOSIX(theFile)))
	on error
		display alert "Logging failed. The log file could not be made."
		return
	end try
	
	-- write string
	set myDate to do shell script "date '+%Y.%m.%d'"
	set myTime to time string of (current date)
	set myData to (myDate & " || " & myTime & ": " & aString & return) as string
	
	-- write
	set OA to open for access theFile with write permission
	try
		write myData as string to OA starting at eof
		close access OA
	on error
		try
			close access OA
		end try
		display alert "Loggin failed. Could not write to file."
		return
	end try
end logError

on HSFWithPOSIX(filename)
	set myAlias to (POSIX file filename)
	set myAlias to myAlias as string
	return myAlias
end HSFWithPOSIX

on stringByExpandingTildeInPath(filename)
	-- get home directory
	set homeDir to POSIX path of (path to home folder)
	if homeDir does not end with "/" then set homeDir to (homeDir & "/") as string
	
	-- if tilde and ev slash
	if filename is "~" then return homeDir
	if filename is "~/" then return homeDir
	
	-- if filename does not contain tilde
	if filename does not start with "~/" then return filename
	
	-- normal filename
	set newName to (homeDir & (characters 3 thru -1 of filename)) as string
	
	return newName
end stringByExpandingTildeInPath

on stringForTerminal(filename)
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to " "
	set allItems to every text item of filename
	set AppleScript's text item delimiters to "\\ "
	set newPath to allItems as text
	
	set AppleScript's text item delimiters to tid
	return newPath
end stringForTerminal

on makeFile(filename, sizeInBytes)
	do shell script "mkfile " & sizeInBytes & "b " & my stringForTerminal(filename)
end makeFile

on sourceOfWebPage(anURL)
	set theSource to missing value
	
	try
		set theSource to do shell script "/usr/bin/curl " & quoted form of anURL
	end try
	
	return theSource
end sourceOfWebPage

on uploadFile(filename, anURL, userName, aPassword)
	set anURL to my encodeTextForURL(anURL, false, false)
	log anURL
	set myName to "/usr/bin/curl "
	set myParam to "-T "
	
	
	-- upload type
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "://"
	try
		set myType to text item 1 of anURL
		set AppleScript's text item delimiters to tid
	on error e
		log "error 1: " & e
		set AppleScript's text item delimiters to tid
		return false
	end try
	
	-- upload path
	try
		set AppleScript's text item delimiters to "://"
		set urlPath to text item 2 of anURL
		set AppleScript's text item delimiters to tid
	on error e
		log "error 2: " & e
		set AppleScript's text item delimiters to tid
		return false
	end try
	
	-- full url
	set AppleScript's text item delimiters to ""
	set fullURLPath to (myType & "://" & userName & ":" & aPassword & "@" & urlPath) as text
	set AppleScript's text item delimiters to tid
	
	set fullCMD to (myName & myParam & quoted form of filename & " " & quoted form of fullURLPath) as string
	
	-- upload
	try
		do shell script fullCMD
		log fullCMD
		return true
	on error e
		log "error 3: " & e
		return false
	end try
end uploadFile

on encodeTextForURL(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to (the encoded_text & this_char)
		else
			set the encoded_text to (the encoded_text & encode_char(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encodeTextForURL

Hope it works,
ief2

Check this link for an easy way to create a python script for sending emails. I use it myself. I created the script and then I can run it from applescript using “do shell script” commands and passing the proper variables. It’s an easy way to send yourself quick text messages without any interaction with a gui.

http://www.cs.cmu.edu/~benhdj/Mac/unix.html#smtpScript

As far as running the script periodically, I use launchd to do that. Running the script at startup is not enough because your external IP could change while you’re using the computer.

This code might cause you a problem:

display dialog "Your External IP Followed By Internal IP is: " & {Ext_IP} & return & {Int_IP} buttons {"Save IP Data", "Cancel"} default button 2 with title "iP Config Stats v1.0" with icon note

Do not put curly braces around Ext_IP and Int_IP. This turns them into lists but a dialog box requires strings, so no braces are needed and probably would cause an error.

The python script above are only helpful if you have an smtp server around which doesn’t need a password or SSL, which I doubt you have.

I have a link to a great little email client which lets you specify the options , you must read the README file. and have a guy at the computer department at school help you with compiling it - you must be along to supply the passwords He/she helps you with the compiling and opening of the files you need to edit your smtp settings and such. I suggest you mail to your school account as you then have the right person at hand for asking about the settings while you configure the email.cfg file.

There is a section in this link http://aplawrence.com/Reviews/cleancodeemail.html named SMTP AUTH
You must check with the helpdesk person about these settings which are the parameters you need to supply in the config file, which can be found in /usr/local/etc/email/email.conf

The link to the email client is here: http://www.cleancode.org/projects/email ; be sure to read the documentation carefully. On Snow Leopard it installs like a breeze.

-By the way:
I had to specify the bindir of the command to get it it installed where it should have been.
The last command in the README file are wrong: it says su -c ‘make install’ but it should have been :sudo make install.
HOWTO (for Snow Leopard):
First of all you must ensure that you have the XCode developer tools installed;
if not install them. (installation CD) + update via internet.

¢ Download the file, email-3.1.2
¢ clicks on the zip file from finder in ‘Downloads’
¢ opens up a terminal window
¢ cd Downloads/email-3.1.2,
¢ more README
while reading the doc in more enter:
! ./configure --bindir=/usr/local/bin
! sudo make install

To edit the file: sudo /usr/local/etc/email/email.conf I haven’t tried this yet but it would be cool if you could avoid having the clear text password there, maybe it works if you: sudo chmod go-r /usr/local/etc/email/email.conf
But if you cant send any mail then you have to : sudo chmod go+r (I haven’t tested it yet).

And that was about it for the installation of the email client which helps you to email the ip-address.

Afterwords:
I can’t make this work because my ISP’s webserver is “quirky” aka it isn’t totally compliant with the TLS/SSL
standards, which also means that I have to tinker the postfix code in order to make a postfix server for relaying mail.:frowning:

Good luck!

You’re right McUsr. I forgot but I modified that script and added smtp support. I uploaded my script to my website. You can see it here: http://www.hamsoftengineering.com/codeSharing/pythonEmail/pythonEmail.html

Hello

I’m sure your script will work in 99% of the cases regulus.
It threw identical messages from the smtp server as any other solution (but any rich client like Mail.app, Thunderbird etc.) does. :slight_smile:

Having said that about the smtp server: Its 100% free from spam!

Best Regards

McUsr