PDA

View Full Version : Can somebody make me a script?




Simo1122
Jan 29, 2009, 07:07 PM
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
Jan 29, 2009, 07:34 PM
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
Jan 29, 2009, 07:42 PM
All i don't know how to do is turn airport ON and disconnect from networks..

Tex-Twil
Jan 30, 2009, 01:20 AM
Hi again ;)
to disconnect airport from the network without turning it off:


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



See help of this command for other usage:


/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
Jan 30, 2009, 01:44 AM
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
Jan 30, 2009, 01:52 AM
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.


#!/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 (http://forums.macrumors.com/showthread.php?p=7023095&posted=1#post7023095)). 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
Jan 30, 2009, 02:38 AM
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
Jan 30, 2009, 04:32 AM
Hey,

How do I enter that sleep thing in this command line

http://h4xr.org/2ha1

Because thats the problem for it not working.

xUKHCx
Jan 30, 2009, 04:41 AM
Seeing as you are in apple script may as well use the delay command between the other commands.

e.g.

delay 10

Tex-Twil
Jan 30, 2009, 06:07 AM
Hey,

How do I enter that sleep thing in this command line


Why do you use an Apple Script if you then use shell script. You can directly use a shell script as I posted before.

T

Simo1122
Jan 30, 2009, 07:25 AM
I'm so confused. I'm only using applescript because thats the only thing i have the slightest grasp on..

Simo1122
Jan 30, 2009, 07:28 AM
Ok now I'm less confused.

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

xUKHCx
Jan 30, 2009, 07:33 AM
Ok now I'm less confused.

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

Yeah straight in

e.g.

do shell script "......
delay 10
do shell script ".....

Tex-Twil
Jan 30, 2009, 07:38 AM
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:

chmod +x myscript


and run :


./myscript


;)

Tex-Twil
Jan 30, 2009, 07:42 AM
Ok now I'm less confused.

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

Yeah straight in

e.g.

do shell script "......
delay 10
do shell script ".....

I think the "you" refered to me :)

Simo1122
Jan 30, 2009, 06:23 PM
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:

chmod +x myscript


and run :


./myscript


;)

No such file or directory
:(

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

Tex-Twil
Jan 31, 2009, 01:21 AM
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:


cd Desktop
chmod +x myscript
./myscript


or



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


T.