Jump to content

Wifi Connect script UPDATED v1.3 v3.0.0 compatible!


SymPak
 Share

Recommended Posts

UPDATE v1.3, Pineapple v2.8.1 and v3.0.0 compatible!

Hi all,

This update brings WPS button cancel to stop the script, ICS improvements including network address detection in case your pineapple is using a different IP address, command execution upon successful connection and general improvements and bug fixes.

Other features include, blacklisting and whitelisting for unencrypted networks, /etc/config/wireless backup, /etc/config/wireless restore, temporarily blacklisting the internal Wifi MAC addresses to prevent it from connecting to itself, automatic internet connection sharing setup, options to start karma once connected, macchanger support for random MAC addresses on both WLAN0 and WLAN1 interfaces, connecting to user specified wifi including encrypted and unencrypted networks and WPS button LED feedback.

More info:

ICS now shares to br-lan by default. Specify what interface you want to share the internet connection to using the -t option.

The /etc/config/wireless file can now be backed up and restored with the script. Run ./connect.sh -B to backup and ./connect.sh -R to restore.

Blacklisting and whitelisting can now be done through the script. Use the -b option to specify an access point you want to blacklist. Use the -w option to specify an access point you want to whitelist. Use the -W option to use the whitelist. Blacklists and whitelists only work with unencrypted wifi networks.

Commands can now be run upon successful connection. Commands are to be placed on their own line in commands.txt in the same directory as connect.sh. Create commands.txt manually, or alternatively by running connect.sh with the -c option. If commands.txt does not exist it will be created. If it does exist the commands will be run as specified in the file.

WPS button LED feedback:

The WPS button LED will flash when the script starts. This means the script is starting. After 30 or 40 seconds count the flashes! There will be a series of flashes followed by a pause. The flashes will then repeat.

Currently there are 3 status states:
If the WPS LED goes solid, the script executed successfully! The pineapple is now connected to Wifi and has an IP address.
If the LED flashes once, it found wifi but was unable to obtain an IP address.
If the LED flashes twice, the pineapple was unable to find any open wifi networks.
If the connection is not successful, the WPS LED will remain off. Restarting the pineapple will restore the LED to normal operation.

Installation

Download the attached file below. Copy or create the wificonnect directory at /pineapple/components/wificonnect/ (or where ever you would like) and place connect.sh in it. SSH into your pineapple, change into the script directory with cd and execute (without quotes): "chmod +x connect.sh".

WPS Button

Pineapple v3.x

Go to the Configuration tile > Button Configuration and add the following to the wps button script (without quotes): "sh /pineapple/components/wificonnect/connect.sh -i wlan1 &" (for external wifi) or "sh /pineapple/components/wificonnect/connect.sh -i wlan0 &" (for internal wifi). IMPORTANT: Keep the & at the end to ensure the script works properly. It is necessary if you would like to use the WPS button to stop the running script.

Alternatively, you can add this to a custom script in the WPS Manager infusion or run it from the terminal.

Pineapple v2.x

Go to the configuration tab in the Pineapple Control Center and add the following to the wps button script (without quotes): "sh /pineapple/components/wificonnect/connect.sh -i wlan1 &" (for external wifi) or "sh /pineapple/components/wificonnect/connect.sh -i wlan0 &" (for internal wifi). IMPORTANT: Keep the & at the end to ensure the script works properly. It is necessary if you would like to use the WPS button to stop the running script.

Alternatively, you can add this to a custom script in the Button infusion or run it from the terminal.

Screenshots

Wifi Connect v1.3
Created by: SymPak

USAGE: ./connect.sh [-BRWkrc] [-i <wlan0|wlan1>] [-s SSID] [-p Wifi Password] [-t Interface] [-b SSID] [-w SSID]...

OPTIONS:
-B      Backup /etc/config/wireless
-R      Restore /etc/config/wireless from backup
-k      Start Karma
-r      Random MAC
-i      Interface
-s      SSID
-p      Wifi Password
-t      To interface for ICS. From interface is specified with -i
-w      Whitelists AP by SSID. Scans with WLAN0 if no interface is specified. Unencrypted netowrks only
-W      Checks for and connects to networks specified in the whitelist. Unencrypted netowrks only
-b      Blacklists AP by SSID. Scans with WLAN0 if no interface is specified. Unencrypted netowrks only
-c      Run commands specified in commands.txt upon successful connection.

Blacklisting and whitelisting screenshot:

root@Pineapple:/pineapple/scripts/wificonnect# ./connect.sh -i wlan1 -b someAP
Starting on wlan1
Scanning for wifi
someAP added to blacklist
Done.
root@Pineapple:/pineapple/scripts/wificonnect# ./connect.sh -i wlan1 -w myAP
Starting on wlan1
Scanning for wifi
myAP added to whitelist
Done.

root@Pineapple:/pineapple/scripts/wificonnect# ./connect.sh -i wlan1 -W
Starting on wlan1
Stopping karma
Scanning for wifi
Checking for whitelisted APs
Found myAP in whitelist.
Connecting to myAP on channel 6 signal quality 72%
Requesting IP Address

Connected
Configuring ICS
Done.

Backup and restore screenshot:

root@Pineapple:/pineapple/scripts/wificonnect# ./connect.sh -B
Wireless configuration file backed up
Done.

root@Pineapple:/pineapple/scripts/wificonnect# ./connect.sh -R
Wireless configuration file restored from backup
Done.


If you encounter any errors please report them here. Also feature requests or improvement suggestions are always welcome!

Note: If you would like to use parts of this script for a script or infusion of your own, contact me by a PM.

-SymPak

wificonnect-v1.3.zip

Edited by SymPak
Link to comment
Share on other sites

Sympak,

How appropriate, I was just about to post a question about connecting to another wifi.

In my setup, i was trying to connect a usb nic to a secured network, I was able to but never got an IP Address. udhcpc just was waiting....

The command I used were...

iwconfig wlan0 mode managed

iifconfig wlan0 up

iwlist wlan0 scan | grep SSID
iwconfig wlan0 essid <networkname> key <networkkey>
udhcpc -i wlan0 -B

Your script looks for strongest open wifi, it wont be to hard to configure a network key and hard code ESSID to connect to.

Edited by dustbyter
Link to comment
Share on other sites

Dustbyter,

I find it better to edit /etc/config/wireless using the uci command. More info about the UCI system and /etc/config/wireless here: http://wiki.openwrt.org/doc/uci

Also, try udhcpc -n -i wlan0. The -n option makes udhcpc exit after 3 failed tries. By default, it just sits and waits after 3 tries.

The next version of my script will include user specific ESSIDs and passkeys.

Link to comment
Share on other sites

Dustbyter. It looks like you're forgetting to put "mode managed" in the iwconfig cmd. Also don't forget that iwconfig will only associate to WEP or OPEN networks. You need wpa_supplicant for WPA/WPA2. Keep in mind the Network Manager infusion works pimp for connecting to a single secured network now since the 2.8.1 update.

SymPak, this script looks sick as hell. Great features. Can't wait for the option to keep a list of user-defined networks with keys! U should add a macchanger -r or -A $WIFI_INT to the beginning.

It would be sick as hell if this could interface with reaver or access the reaver infusion somehow. Lol the Jammer would be sweet too before Karma starts. That would really automate things!!!

Sorry I'm getting carried away q=]

Edited by kpoeticg
Link to comment
Share on other sites

Thanks! I could have kept adding features, but I did not want to get ahead of myself. I am currently working on adding the list of user defines networks and setting up ICS once it has an ip address. After that I will begin work on an infusion to act as a control interface. Adding a macchanger is a good idea! I will look into implementing it.

Link to comment
Share on other sites

  • 2 weeks later...

Just a small status update. Version 1.1 will be out soon with some new features!

Features will include:

User specific wifi (encrypted and unencrypted)

Option to start karma once connected

Option to change to a random MAC address

Automatic setup of internet connection sharing between wifi interfaces.

I would also like to get some feedback from those of you who have tried my script. Has it worked for you? Have you had issues running it? Anything helps.

-SymPak

Link to comment
Share on other sites

When I try to run the script its comes back with permission denied?

Ive tried it in advanced tab and it says nothing and also tried it in putty, ive done chmod..

I noticed my internal wifi card is on wlan0 not wlan1 also.

any suggestions? really want to get this up and running!

Dave

Link to comment
Share on other sites

Did you remember to chmod +x ?

Nvm, just saw where u said you did. Internal wifi should be on wlan0 unless u change it. If u chmod +x it shouldn't come back with permission denied. When you're in putty and u do a " ls " in the directory does it show the script in green letters or white?

Edited by kpoeticg
Link to comment
Share on other sites

Version 1.1r2 fixes an error in the script. Each line was filled with ^M characters, which caused the script not to run properly.

-SymPak

Link to comment
Share on other sites

Dave, how did you go about putting the script on your pineapple? Starting the script on wlan0 is simple. Just run ./connect.sh -i wlan0

Link to comment
Share on other sites

I put it in pineapple/scrips/connectwifi with winSCP

any idea why my internal card is coming up as wlan1 ? I'm guessing it's the internal because when I run iwconfig it gives me 27dbi on wlan0 and 18 or something on wlan1 (at work right now so can't check)

I did the chmod, tried it with putty and with winSCP..

When I do factory reset it still loads the wifi the wrong way around I'm using the Alfa awus036h, I'm assuming this card works as it does with everything I've tried in the past..?

Link to comment
Share on other sites

I still have that problem with the awus036H...It happens to me when the unit is booted with the Alfa already plugged in...I usually just plug it in post-boot and it is assigned wlan1 as expected. Thought I read somewhere around here that the issue is resolved when using the awus036NH, but maybe not with the 36H...I am using 2.81 Final BTW.

-Fugged

Link to comment
Share on other sites

Thanks got it to a further point now but still getting errors in the script,
Ran iwconfig and it says the wifi is up then I run the script and it says the wifi is unavailable?
Then if i run iwconfig again after running the script it says the wifi is now down :s
any ideas?
here is the output:
root@Pineapple:/pineapple/scripts/wificonnect# iwconfig
lo        no wireless extensions.

wlan1     IEEE 802.11bg  ESSID:off/any
          Mode:Managed  Access Point: Not-Associated   Tx-Power=27 dBm
          RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off

eth1      no wireless extensions.

wlan0     IEEE 802.11bgn  Mode:Master  Tx-Power=18 dBm
          RTS thr:off   Fragment thr:off
          Power Management:on

eth0      no wireless extensions.

br-lan    no wireless extensions.

root@Pineapple:/pineapple/scripts/wificonnect# ./connect.sh -i wlan1
Stopping karma
Starting on wlan1
Scanning for wifi
Scan not completed. Retrying. 1 of 3
Scan not completed. Retrying. 2 of 3
Scan not completed. Retrying. 3 of 3
Cannot scan for wifi. Interface down or unavailable.
Done.


Edit: Same error when I remembered to specify the -s and -p functions

Edited by Davepheadrus
Link to comment
Share on other sites

Thats not an /etc/config/wireless issue. Thats an issue with the iwlist command. The interface isn't allowing a scan to be completed. Try executing iwlist wlan1 scan and see what errors it gives

Link to comment
Share on other sites

Davepheadrus,

What firmware are you using for your pineapple? Doesn't the ifconfig command show the MAC address of the devices? That should help you determine which is which wlan device... By the TX power I'd say your internal is wlan0 at 18. And you must have an Alpha with "iw reg set" to another county to get 27 on wlan1? Just guessing.

Link to comment
Share on other sites

wlan1     Failed to read scan data : No such device

thats what i get for "wlist wlan1 scan" if i do ifconfig wlan1 up before it.

if i do it without ifconfig wlan1 up then it says:

wlan1     Interface doesn't support scanning : Network is down

@thesugarat Im running the newest (2.8.1? idk) but I flashed only a few days ago onto whatever was the newest..

& it is the alfa, I only get 27 dBm when i plug the alfa in after reboot and then do 'ifconfig wlan1 up' otherwise it just says 0.

and after any task at all it goes back to 0.

what do you mean about other country's? I live in the UK if that has anything to do with anything..

Cheers, Dave

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...