Applescript for MAC address list updates

Hello all,

I am pretty new not only here, but to AppleScripts as well.

I found this http://www.macosxhints.com/article.p...71228144426216 which will automatically restart an airport extreme, but it only does the first one on the list.

I am in a business environment that has 4 airport extremes. What I’d like to do is be able to update the MAC address filter list on all of them automatically, either hard coded in, or from a text file.

I was wondering if some one could offer some assistance.

From UI Browser, I can see that the list is in a scroll area (1) then in table 1 where there are 5 rows (4 air ports and 1 time capusel). I need a script that checks the values of each and compares it to the name that we want.

Name 1
Name 2
Name 3
Name 4

For each row compare the name to the first on the list (Name 1) and select that table row. Then run some other script to add the new information, restart the airport, wait then loop back through selecting the second name.
Lather rinse repeat.

I am really having trouble getting started with the selector, I think I may have the ability to do the rest of the coding.

Thank you for your help.
Keegan

Hi,

here is some code to GUI script Airport Utility.

Hope it helps

http://macscripter.net/viewtopic.php?id=22477

Perfect! Thank you!

In appreciatiion for the informaion, I’ll share my newly created script.

This script updates the MAC address filters on the airport extremes.

set macList to {} --fill in with a list of mac addresses
set descList to {} --fill in with a list of descriptions of the mac addresses

set airPortList to {} --fill in with the names for your airports
-- 

if (descList's length is not equal to macList's length) then
	display dialog "Check the lists! They don't have the same number of elements!"
end if

set y to 1
repeat until y is (airPortList's length) + 1
	activate application "AirPort Utility"
	if character 1 of (get version of application "AirPort Utility") as integer < 5 then return -- Versioncheck
	tell application "System Events"
		tell process "AirPort Utility"
			delay 3
			tell window 1
				tell (1st row of table 1 of scroll area 1 whose value of text field 1 is (get item y of airPortList))
					set value of attribute "AXSelected" to true
				end tell
			end tell
			tell menu bar 1
				click menu bar item "Base Station"
				
				tell menu bar item "Base Station"
					tell menu 1
						click menu item "Manual Setup"
					end tell
				end tell
			end tell
			delay 5
			tell window 1
				tell tab group 1
					click radio button 4
					delay 1
					repeat until not (exists (row 2 of table 1 of scroll area 1))
						tell (row 2 of table 1 of scroll area 1)
							set value of attribute "AXSelected" to true
						end tell
						click button 3 --Delete entry button
					end repeat
				end tell
				
				set x to 1
				repeat until x is (macList's length) + 1
					set mac to (get item x of macList)
					set desc to (get item x of descList)
					tell tab group 1
						click button 2 --Add entry button
					end tell
					tell sheet 1
						tell text field 1
							keystroke mac & tab & tab
						end tell
						tell text field 2
							keystroke desc
						end tell
						click button 2 -- Done button
					end tell
					set x to x + 1
				end repeat
				click button 7
				delay 30
			end tell
			
		end tell
	end tell
	quit application "AirPort Utility"
	delay 5
	set y to y + 1
end repeat

I hope someone else will find this useful.

OK so I was taking a look at this script again, and I could use some help.

The macList is a list of MAC address ( “111111111111”, “222222222222” etc). I was wondering if some one could rig up a quick script that steps through the list and verifies that the MAC addresses are of the correct format. (12 characters, 0-F)

I am just not really sure how to do this.

This is what I have so far:


set macTest to 1
	set badMAC to 0
	set badMACList to ""
	set mac to ""
	set TORF to true -- stands for True OR False. This is just to controll the next section. 
	repeat until macTest is (macList's length) + 1
		set mac to (get item macTest of macList)
		-- check the length of the MAC address
		if length of mac is not equal to 12 then
			set badMAC to badMAC + 1
			set badMACList to badMACList & " #" & macTest & " " & mac
			set TORF to false --if its false, the second check does not need to occur on the address
		end if
		
		-- check the elements of the MAC address to verify they are correct.
		
		set ecTORF to 0 -- this is to control to make sure that once an element fails, the whole string does.
		
		if TORF then
			set elementCheck to 1
			repeat until (elementCheck is (mac's length) + 1)
				--display dialog "Passed first"
				set element to text elementCheck of mac
				--display dialog element
				if (class of element is not integer) and (element is not equal to "A") and (element is not equal to "B") and (element is not equal to "C") and (element is not equal to "D") and (element is not equal to "E") and (element is not equal to "F") then
					set badMAC to badMAC + 1
					set badMACList to badMACList & " #" & macTest & " " & mac
					set elementCheck to (mac's length)
				end if
				set elementCheck to elementCheck + 1
			end repeat
		end if
		
		set macTest to macTest + 1
	end repeat
	
	if badMAC > 0 then
		display dialog "There are " & badMAC & " bad MAC address. Please verify the list."
		display dialog "Problem MACs: " & badMACList
	else
		

I am just not sure about iterating through the list of strings and making sure they fall under the 0-F. This code, the MAC addresses always fail.

Nevermind, I figured it out. Here is the updated script incase anyone needs it.


--Created by: Keegan Shaw
--Date: 12/17/2009
--Last Modify Date: 10/28/2010
--This script changes the MAC address list located in the AirPort Extreme. It uses AirPort Utility to make this changes. This is located in the Utilities folder on most Macs. 
--Created using version 5.5 of the AirPort Utility. 

--Update the macList and the descList with the new mac address (or remove entries from BOTH lists). Then click on run. 
--To update a new AirPort, simply add it to the airPortList.

set macList to {""}

set descList to {""}

set airPortList to {""}
--

if (descList's length is not equal to macList's length) then
	display dialog "Check the lists! They don't have the same number of elements!"
else
	
	--set global variables
	global badMAC, badMACList, mac
	
	set macTest to 1
	set badMAC to 0
	set badMACList to ""
	set mac to ""
	set TORF to true -- stands for True OR False. This is just to controll the next section. 
	repeat until macTest is (macList's length) + 1
		set mac to (get item macTest of macList)
		-- check the length of the MAC address
		if length of mac is not equal to 12 then
			set badMAC to badMAC + 1
			set badMACList to badMACList & " #" & macTest & " " & mac
			set TORF to false --if its false, the second check does not need to occur on the address
		end if
		
		-- check the elements of the MAC address to verify they are correct.
		
		set ecTORF to 0 -- this is to control to make sure that once an element fails, the whole string does.
		
		if TORF then
			set elementCheck to 1
			repeat until (elementCheck is (mac's length) + 1)
				set element to text elementCheck of mac
				if (element is not equal to "0") and (element is not equal to "1") and (element is not equal to "2") and (element is not equal to "3") and (element is not equal to "4") and (element is not equal to "5") and (element is not equal to "6") and (element is not equal to "7") and (element is not equal to "8") and (element is not equal to "9") and (element is not equal to "A") and (element is not equal to "B") and (element is not equal to "C") and (element is not equal to "D") and (element is not equal to "E") and (element is not equal to "F") then
					set badMAC to badMAC + 1
					set badMACList to badMACList & " #" & macTest & " " & mac
					set elementCheck to (mac's length)
				end if
				set elementCheck to elementCheck + 1
			end repeat
		end if
		
		set macTest to macTest + 1
	end repeat
	
	if badMAC > 0 then
		display dialog "There are " & badMAC & " bad MAC address. Please verify the list."
		display dialog "Problem MACs: " & badMACList
	else
		
		set y to 1
		repeat until y is (airPortList's length) + 1
			activate application "AirPort Utility"
			if character 1 of (get version of application "AirPort Utility") as integer < 5 then return -- Versioncheck
			tell application "System Events"
				tell process "AirPort Utility"
					delay 3
					tell window 1
						tell (1st row of table 1 of scroll area 1 whose value of text field 1 is (get item y of airPortList))
							set value of attribute "AXSelected" to true
						end tell
					end tell
					tell menu bar 1
						click menu bar item "Base Station"
						
						tell menu bar item "Base Station"
							tell menu 1
								click menu item "Manual Setup"
							end tell
						end tell
					end tell
					delay 15
					tell window 1
						tell tab group 1
							click radio button 4
							delay 1
							repeat until not (exists (row 2 of table 1 of scroll area 1))
								tell (row 2 of table 1 of scroll area 1)
									set value of attribute "AXSelected" to true
								end tell
								click button 3 --Delete entry button
							end repeat
						end tell
						
						set x to 1
						repeat until x is (macList's length) + 1
							set mac to (get item x of macList)
							set desc to (get item x of descList)
							tell tab group 1
								click button 2 --Add entry button
							end tell
							tell sheet 1
								tell text field 1
									keystroke mac & tab & tab
								end tell
								tell text field 2
									keystroke desc
								end tell
								click button 2 -- Done button
							end tell
							set x to x + 1
						end repeat
						click button 7
						delay 30
					end tell
					
				end tell
			end tell
			quit application "AirPort Utility"
			delay 5
			set y to y + 1
		end repeat
	end if
end if