Simple Soloution

Discussion in 'Mac Programming' started by devan963, Aug 24, 2010.

  1. devan963 macrumors newbie

    Joined:
    Aug 23, 2010
    #1
    I am currently writing a script to load certain preferences dependent on my location. I have managed to use my Broadcast and static IP address to identify a particular network and get my script to compare them to see if i am at home, work, etc,

    However i think the best way of getting it so it is always accurate is to use the networks BSSID, I know i can find it by option > right click on the airport icon but how can i get the information in to a script, Can i find the BSSID from the command line?

    I use the below to get current IP address:
    Code:
    set ipAddr to {do shell script "ifconfig en0 | grep 'inet ' | awk '{print $2}' ", do shell script "ifconfig en1 | grep 'inet ' | awk '{print $2}'"}
    
    Is there something that will get the BSSID?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Code:
    system_profiler | grep SSID_STR
    returns the Airport SSID I am connected to...

    Edit: but it also returns others :(

    Edit again: system_profiler SPAirPortDataType gives just the current Airport config: you might be able to parse that...
     
  3. jazzbo macrumors member

    Joined:
    Oct 11, 2008
    Location:
    Bangor, ME
    #3
    I've done something similar as I have a custom login script based on my location, and to check my SSID I use the result of the following command:

    Code:
    /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | /usr/bin/grep " SSID:" | /usr/bin/awk '{print $2}'
     
  4. devan963 thread starter macrumors newbie

    Joined:
    Aug 23, 2010
    #4
    I have looked further into the system_profiler (thanks for the pointer robbie) and come up with this solution:

    Code:
    system_profiler -detailLevel full | grep 'Network Signature'| awk '{print $3;}'
    This gives
    Code:
    IPv4.Router=192.168.1.1;IPv4.RouterHardwareAddress=00:22:00:22:00:22  
    
    (I have changed the MAC)

    Jazz, While your solution is much neater I am looking to check the en0 and en1 interfaces, e.g. i can be connected to either at different locations, I have looked quickly but i cant see how to get the same details for Ethernet

    One thing that is very annoying is that whenever i use the system_profiler it comes up :
    Code:
    This command still works, but it is deprecated. Please use launchctl(8) instead.
    This command still works, but it is deprecated. Please use launchctl(8) instead.
    This command still works, but it is deprecated. Please use launchctl(8) instead.
    
    Again i have looked quickly at launchctl but with it not being familiar i am unsure of how to use it
     
  5. jazzbo macrumors member

    Joined:
    Oct 11, 2008
    Location:
    Bangor, ME
    #5
    Ah, missed the part that you were dealing with ethernet. I don't usually think of a BSSID on a wired network.

    Code:
     ping -c 1 `ipconfig getoption en1 router` | arp -a | grep `ipconfig getoption en1 router` | awk '{print $4;}'
    
    Convoluted in that it would be more efficient to stick the router ip into a variable, but as a brief proof of concept I think the above may do what you want -- i.e. it should return the mac address of your router. The ping may not be necessary, but doing so should ensure it is in your arp cache.
     
  6. devan963 thread starter macrumors newbie

    Joined:
    Aug 23, 2010
    #6
    After looking into all of the suggestions i think that the below is the best for the script, i.e. it is fast to respond and it brings up the MAC address and IP address of the network.

    It also has none of the depreciation errors.

    Code:
    system_profiler SPSoftwareDataType SPNetworkDataType | grep 'Network Signature'| awk '{print $3;}'
    
     

Share This Page