PDA

View Full Version : script to check MAC address & then output display message


MacLahoriya
2009-06-27, 03:58
hi.....

i need your help to create a small script. i don't know scripting, and mostly copy/paste from net if i need something basic.

so the situation is that i have enabled Remote Access on my PowerBook (on LAN side) which is behind my Tomato router (ssh enabled on router). No open ports on the router so i think i am somewhat secure.

Now, if i get connect to internet through some other router I just want to remind myself to turn off the Remote Access. I plan to do this via GeekTool to display a message on my Desktop.

I have found that this terminal command

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I|grep BSSID|awk {'print $1 " "$2'}

does display the BSSID (MAC address) of the router you are connected to. But I don't know how to implement it in a script. I am sure it is very easy for someone who knows scripting. I have a basic sketch:

Check BSSID
if 00:00:00:00:00:0
then output text Connected to Tomato Router
if it is not 00:00:00:00:00:0
then output text NOT CONNECTED TO TOMATO ROUTER

(**if possible to add to above script, otherwise it is ok even without below part**
if airport is turned off
then Airport is INACTIVE)

I will be thankful for your help. i am not sure if it can be appleScript or shell-script to implement via GeekTool.

Cheers :)

Brad
2009-06-27, 13:21
Any particular kind of script? Here's a quickie bash script:


#!/bin/bash
tomato="00:00:00:00:00:0"
address=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I|grep BSSID|awk {'print $2'}`

if [ $address == $tomato ]
then
echo "Connected to Tomato Router"
else
echo "NOT CONNECTED TO TOMATO ROUTER"
fi


Drop this into a text file (like "tomato.sh") and from the Terminal give it the executable bit (chmod +x tomato.sh) before running it.


$ cd Desktop/
$ chmod +x tomato.sh
$ ./tomato.sh
NOT CONNECTED TO TOMATO ROUTER

MacLahoriya
2009-06-27, 16:34
oh really thanks Brad. i will give it a try following your instructions.

cheers.

MacLahoriya
2009-06-27, 16:51
i tried it. it works. dutifully tells it is connected to my own router.

thanks again.

Brad
2009-06-27, 17:50
Great! Glad to have helped. :)