Results 1 to 8 of 8

Thread: Simple script for wpa_supplicant

  1. #1
    Member
    Join Date
    Jun 2008
    Posts
    101

    Default Simple script for wpa_supplicant

    I recently installed BT3 to my HDD, so I was thinking on a way to run wpa_supplicant automatically! I'm assuming that wpa_supplicant.conf is properly configure and ready to execute when called.

    First create a bash file using an editor, save without extension

    #!/bin/bash
    clear
    ifconfig ath0 up
    echo "starting wpa_supplicant"
    wpa_supplicant -w -D wext -i ath0 -c /etc/wpa_supplicant.conf
    # chmod 755 filename -read,write,exe privileges

    # ./filename -execute the file

    Next, open a terminal and get an ip

    # dhcpcd ath0

    Done! I'm also looking for a way of opening a second terminal in the script in order to execute dhcpcd as well. After that find a way of running this automatically at startup!

    Ideas are welcome. Thx

  2. #2
    Just burned his ISO Niros's Avatar
    Join Date
    May 2007
    Posts
    16

    Default

    By the looks of things it only supports atheros cards. Perfect for the EEEPC however, this is getting added into my modules folder. Thanks for the code

  3. #3
    Member
    Join Date
    Jun 2008
    Posts
    101

    Default

    Yes, my chipset is atheros, but I think you can easily adapt it to any other chipset. I added something extra, -B to run wpa_supplicant deamon in the background, and dhcpcd to get the IP!

    #!/bin/bash
    clear
    echo "turning ath0 interface up..."
    ifconfig ath0 up
    echo "starting wpa_supplicant"
    wpa_supplicant -B -D wext -i ath0 -c /etc/wpa_supplicant.conf
    echo "obtaining ip..."
    dhcpcd ath0

    exit

  4. #4
    Just burned his ISO
    Join Date
    Jul 2008
    Posts
    3

    Default Wireless in Slackware based systems.

    Hi, I'm new to BackTrack but I've been using Slackware for a while now... I know this thread's a bit old, but thought I'd stick my oar in anyway, and hopefully teach somebody something. In Slack 12 (might be slightly different in 12.1), edit /etc/rc.d/rc.inet1.conf and scroll down to the section commented as 'Example config information for wlan0'. All you need to do is uncomment (remove the # at the beginning) each line you will need. For a pretty standard WPA-PSK DHCP setup, you should just need to uncomment IFNAME[4] and change the value to the name of your wifi device (ath0, eth1, wlan0 etc), USE_DHCP[4] (set it to "yes" - lower case). Next uncomment WLAN_ESSID[4] and put in your own... Next up WLAN_MODE[4] - set it to 'Managed'. WLAN_KEY[4] needs to be set to your PSK, and WLAN_WPA[4] should be "wpa_supplicant".

    This should get it all going from startup, as /etc/rc.d/rc.inet1 script runs during startup.

    It may all seem a bit daunting to those new to linux, but you're gonna have to get dirty sooner or later These scripts are really useful to know back to front for anything network related.

    P.S. If you really want to use your own script to connect, then just edit /etc/rc.d/rc.local and add a new line which is the location of your script. That will cause it to run this script as soon as the machine finishes it's init scripts.

    X-T

  5. #5
    Member
    Join Date
    Jun 2008
    Posts
    101

    Default

    Quote Originally Posted by xtothat View Post
    Hi, I'm new to BackTrack but I've been using Slackware for a while now... I know this thread's a bit old, but thought I'd stick my oar in anyway, and hopefully teach somebody something. In Slack 12 (might be slightly different in 12.1), edit /etc/rc.d/rc.inet1.conf and scroll down to the section commented as 'Example config information for wlan0'. All you need to do is uncomment (remove the # at the beginning) each line you will need. For a pretty standard WPA-PSK DHCP setup, you should just need to uncomment IFNAME[4] and change the value to the name of your wifi device (ath0, eth1, wlan0 etc), USE_DHCP[4] (set it to "yes" - lower case). Next uncomment WLAN_ESSID[4] and put in your own... Next up WLAN_MODE[4] - set it to 'Managed'. WLAN_KEY[4] needs to be set to your PSK, and WLAN_WPA[4] should be "wpa_supplicant".

    This should get it all going from startup, as /etc/rc.d/rc.inet1 script runs during startup.

    It may all seem a bit daunting to those new to linux, but you're gonna have to get dirty sooner or later These scripts are really useful to know back to front for anything network related.

    P.S. If you really want to use your own script to connect, then just edit /etc/rc.d/rc.local and add a new line which is the location of your script. That will cause it to run this script as soon as the machine finishes it's init scripts.

    X-T
    Nice, I'll definitely try it out when I have some free time. I'll give you some feedback afterward.

  6. #6
    Just burned his ISO
    Join Date
    Jul 2008
    Posts
    3

    Default Can't wait

    I look forward to your reply!

    X-T

  7. #7
    Member
    Join Date
    Jun 2008
    Posts
    101

    Default

    Quote Originally Posted by xtothat View Post
    I look forward to your reply!

    X-T
    Sorry it took me so much time. This school summer term in driving me nuts... Anyways, I started by doing what you first told me, configuring rc.inet1.conf, but no matter what values I gave, it wouldn't do a thing. It was like if rc.inet1 wasn't using the .conf file at all. So then I went and edited the rc.inet1 executable itself, and added the wpa_supplicant script. You actually led me to this, the only thing is that for some reason I did it on rc.inet1 instead of rc.local like you told me. Well, everything is working perfectly now... This how rc.inet1 looks like after inserting the tiny script:

    #! /bin/sh
    # /etc/rc.d/rc.inet1
    # This script is used to bring up the various network interfaces.
    #
    # Modified for SLAX by Tomas M. <htttp://slax.linux-live.org>
    #

    if [ "$1" = "start" -o "$1" = "" ]; then

    ifconfig lo down 2>/dev/null
    /sbin/ifconfig lo 127.0.0.1 2>/dev/null
    /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo 2>/dev/null

    # here is how to setup wifi device easily.
    # First type 'iwconfig' command to see which devices are WIFI-enabled
    # In this example, eth0 is our wifi device:
    #
    # mac address of your access point
    # iwconfig eth0 ap 11:23:b5:13:43:16

    # channel value. You may skip this one, but some drives require this
    # iwconfig eth0 channel 11

    # security key for WEP, if you are using it
    # iwconfig eth0 key a43b436a3c6236b4a3c5d2b5a3

    # your network name
    # iwconfig eth0 essid my_network

    # now enable the device so dhcpcd can see it in the next step
    # ifconfig eth0 up
    #
    # end of wifi sample configuration

    for eth in `ls /sys/class/net | grep -v sit`; do
    # check if dhcpcd is not already running for $eth interface,
    # in that case it was started by hotplug? so don't start it again
    if [ "$eth" != "lo" -a ! -e /etc/dhcpc/dhcpcd-$eth.pid ]; then
    echo "Auto Configure IP address for $eth: /sbin/dhcpcd -t 60 $eth &"
    /sbin/dhcpcd -t 60 $eth &
    fi
    done

    # Custom Code for wpa_supplicant configuration...

    echo "Starting wpa_supplicant configuration..."
    wpa_supplicant -w -B -i ath0 -D wext -c /etc/wpa_supplicant.conf
    dhcpcd ath0

    fi
    Clarify this for me, there is nothing in this shell script calling for inet1.conf... Or am I overlooking this? Thx

  8. #8
    Just burned his ISO
    Join Date
    Jul 2008
    Posts
    3

    Default

    Hi there. Riiiight. Just booted into BT3 and you're quite right, there is no link between the 2 files. Sorry to mislead, I assumed that seeing as BT3 is Slackware 12.1 based that it would use Slack 12.1 scripts. As it is, I think you've probably done the best thing there with adding it to rc.inet1.

    As a kind of explanation of why it works with your entry... On boot, the system runs a series of scripts. These are located in the /etc/rc.d directory, and all started by the scripts named rc.S and rc.M (rc.K is for shutdown).

    rc.S is for when the system is in single user mode, where all kernel-essential services will be started.

    rc.M is started when the system goes into multi-user mode, where all of your installed services will start.

    If you search in rc.M, you will see that rc.inet1 is called with the command:

    Code:
    if [ -x /etc/rc.d/rc.inet1 ]; then
     . /etc/rc.d/rc.inet1
    fi
    rc.local runs after rc.S and rc.M, and is where you would start any user services. I tend to (in a generally disorganised fashion!) just stick any scripts I need to run on startup from there.

    If ever you need to add anything to these, or change any of the text which scrolls past, feel free. I usually tend to leave it all as is, but you are given total freedom (don't you love Linux already!).

    Anyway, yet again, sorry for sending you on a wild goose chase, and I hope your adventures with Linux are as awesome as mine have been! I've been playing with making my Atheros internal wi-fi act as a rogue AP!!! Great fun!

    X-T

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •