Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Simo1122

macrumors member
Original poster
Jan 28, 2009
60
0
I have no idea how to make scripts but I would love if somebody could make one for me

I want it to do this (I have been doing it via terminal)

1. Turn Airport ON

2. Disconnect it from any network.

3. sudo ifconfig en1 lladdr (mac address here)

4. Connect it to (my wireless network)

I want it to be able to be changed script editor so I can enter my MAC address and the network name I want it to join. If it's possible.

The network reconnect is not very important but it would be good..
 

twoodcc

macrumors P6
Feb 3, 2005
15,307
26
Right side of wrong
I have no idea how to make scripts but I would love if somebody could make one for me

I want it to do this (I have been doing it via terminal)

1. Turn Airport ON

2. Disconnect it from any network.

3. sudo ifconfig en1 lladdr (mac address here)

4. Connect it to (my wireless network)

I want it to be able to be changed script editor so I can enter my MAC address and the network name I want it to join. If it's possible.

The network reconnect is not very important but it would be good..

so you are doing all of this in the terminal already?
 

Simo1122

macrumors member
Original poster
Jan 28, 2009
60
0
All i don't know how to do is turn airport ON and disconnect from networks..
 

Tex-Twil

macrumors 68030
May 28, 2008
2,501
15
Berlin
Hi again ;)
to disconnect airport from the network without turning it off:

Code:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -z

See help of this command for other usage:

Code:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -help
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport AirPort v.524.1 (524.1.0)
Supported arguments:
 -z        --disassociate       Disassociate from any network
 -i[<arg>] --ibss=[<arg>]       Create IBSS
 -x        --xml                Print info as XML
 -s[<arg>] --scan=[<arg>]       Perform a wireless broadcast scan.
				   Will perform a directed scan if the optional <arg> is provided
 -r<arg>   --repeats=<arg>      Repeat the command the specified number of times
 -A[<arg>] --associate=[<arg>]  Associate to network.
				   Will prompt for network name if arg is not specified
				   and if necessary, for a password if the network is using WEP or WPA.
				   The following additional arguments may be specified with this command:
                                  --bssid=<arg>     Specify BSSID to associate with
                                  --password=<arg>  Specify a WEP key or WPA password
 -I        --getinfo            Print current wireless status, e.g. signal info, BSSID, port type etc.
 -P<arg>   --psk=<arg>          Create PSK from specified pass phrase and SSID.
				   The following additional arguments must be specified with this command:
                                  --ssid=<arg>      Specify SSID when creating a PSK
 -c[<arg>] --channel=[<arg>]    Set arbitrary channel on the card
 -h        --help               Show this help
 

Simo1122

macrumors member
Original poster
Jan 28, 2009
60
0
Hey Tex,
Thanks for the help. So far I have nearly got it except how do I make it enter a password under LEAP? Not WEP or the others.

If I have the wireless network saved in system prefs, if I tell it to join it should it do it automatically? (I can't test it until monday)
 

Tex-Twil

macrumors 68030
May 28, 2008
2,501
15
Berlin
I dont know how to turn ON the airport via command line but the script could look like this. Note that the password of the wlan is stored in the script so make sure that it is readable only by root.

Code:
#!/bin/bash 

AIRPORT_BIN="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport"

# name and password (!!) for your wlan
MY_ESSID="my_wlan"
MY_PASSWORD="my_password"


IF_BIN="/sbin/ifconfig"
IFACE="en1"

NEW_MAC="00:23:12:xx:xx:xx"

# disconnect
$AIRPORT_BIN -z

# wait 10 seconds !
sleep 10

# change the mac
$IF_BIN $IFACE lladdr $NEW_MAC


#reconnect
$AIRPORT_BIN --associate=$MY_ESSID --password=$MY_PASSWORD

We are not sure how to change the mac of the airport correctly (see your previous post). It looks like the mac is NOT changed if it ifconfig is executed just after the disconnect command and that"s why I put a sleep of 10 seconds.

This is just a very quick script that could/should be enhanced.

Cheers,
Tex
 

Tex-Twil

macrumors 68030
May 28, 2008
2,501
15
Berlin
Hey Tex,
Thanks for the help. So far I have nearly got it except how do I make it enter a password under LEAP? Not WEP or the others.

If I have the wireless network saved in system prefs, if I tell it to join it should it do it automatically? (I can't test it until monday)

I don't think that it will use the password automatically. The LEAP authentication might be a problem since the command line tool doesn't seem to have a parameter for such a password. Just try and see.
 

Simo1122

macrumors member
Original poster
Jan 28, 2009
60
0
Hey,

How do I enter that sleep thing in this command line

2ha1


Because thats the problem for it not working.
 

xUKHCx

Administrator emeritus
Jan 15, 2006
12,583
9
The Kop
Seeing as you are in apple script may as well use the delay command between the other commands.

e.g.

delay 10
 

Simo1122

macrumors member
Original poster
Jan 28, 2009
60
0
I'm so confused. I'm only using applescript because thats the only thing i have the slightest grasp on..
 

Simo1122

macrumors member
Original poster
Jan 28, 2009
60
0
Ok now I'm less confused.

The thing you posted above, can I put that in script editor?
 

Tex-Twil

macrumors 68030
May 28, 2008
2,501
15
Berlin
Ok now I'm less confused.

The thing you posted above, can I put that in script editor?
No. The bash script is just a sequence of bash (~=Terminal) commands that you put in a text file and then execute the file.

So copy and paste the script I posted in a text file, save the file somewhere e.g. myscript. Then in a terminal, make it executable:
Code:
chmod +x myscript

and run :

Code:
./myscript

;)
 

Simo1122

macrumors member
Original poster
Jan 28, 2009
60
0
No. The bash script is just a sequence of bash (~=Terminal) commands that you put in a text file and then execute the file.

So copy and paste the script I posted in a text file, save the file somewhere e.g. myscript. Then in a terminal, make it executable:
Code:
chmod +x myscript

and run :

Code:
./myscript

;)

No such file or directory
:(

Do i have to save it somewhere specific or add to your terminal line?
 

Tex-Twil

macrumors 68030
May 28, 2008
2,501
15
Berlin
No such file or directory
:(

Do i have to save it somewhere specific or add to your terminal line?
Well zou have to be in the same directory where your "myscript" file is. If you create it on your Desktop, you first have to "cd" to your Desktop:

Code:
cd Desktop
chmod +x myscript
./myscript

or


Code:
chmod +x /Users/yourlogin/Desktop/myscript
/Users/yourlogin/Desktop/myscript

T.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.