It is currently Wed May 22, 2013 10:09 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [SOLVED] script to connect to network
PostPosted: Wed May 16, 2007 8:08 am 
Regular Zenwalker
Regular Zenwalker

Joined: Thu May 03, 2007 3:44 pm
Posts: 25
Hi I need some help to improve my network connection script.
Code:
#!/bin/sh
wpa_supplicant -B -i eth1 -w -D wext -c /etc/wpa_net.conf
sleep 3
dhcpcd eth1

You notice the sleep 3... I wanna know if there is a way to know if wpa_supplicant successfully coonnected to the network so then I do dhcpd eth1.


Last edited by hyperion on Fri Jun 01, 2007 1:40 pm, edited 1 time in total.

 Profile Send private message  
 
 Post subject: Re: script to connect to network
PostPosted: Wed May 16, 2007 6:23 pm 
Master of the known universe
Master of the known universe
User avatar

Joined: Mon Aug 28, 2006 11:57 am
Posts: 1040
Location: Karlsruhe, Germany
Just connect them with like this:
wpa_supplicant (.........) -c /etc/wpa_supplicant.conf && dhcpcd

This way, dhcpcd is only called if wpa_supplicant was run succsessfully.

_________________
...and just when you thought, the shadows were safe...


 Profile Send private message  
 
 Post subject: Re: script to connect to network
PostPosted: Wed May 16, 2007 6:45 pm 
Master Zenwalker
Master Zenwalker
User avatar

Joined: Wed Oct 25, 2006 4:47 pm
Posts: 582
Location: ever closer to bliss ....
I wrote this for WEP.  You might find it useful:

Code:
# Function to configure ath0 and obtain a DHCP IP address
dhcp_get() {
  echo "Configuring interface ...";
  iwconfig $device essid $essid key $key ;
  echo "Acquiring IP Address ... ";
  dhcpcd -d -t 10 $device;
  # The following will check if there was an IP addr issued
  if [[ -f /etc/dhcpc/dhcpcd-ath0.pid ]]
  then
    echo "Connection ready!";
    echo ;
    iwconfig $device ;
    ifconfig $device ;
    exit 0 ;
  else
    echo "Connection attempt unsuccessful.";
    echo ;
    iwconfig $device ;    # dhcpcd will automatically bring ath0 down
    exit 101 ;
  fi
}


The whole script: http://www.mooworld.org/src/bash/getwifi1

_________________
ThinkZen member #000
Proud Thinkpad Zenwalker


 Profile Send private message  
 
 Post subject: Re: script to connect to network
PostPosted: Fri May 18, 2007 2:30 am 
Experienced Zenwalker
Experienced Zenwalker
User avatar

Joined: Tue Aug 22, 2006 2:10 pm
Posts: 241
Location: Ohio
#!/bin/bash
INTERFACE=eth0
/usr/sbin/wpa_supplicant -Bw -D wext -i ${INTERFACE} -c /etc/wpa_supplicant.conf
/sbin/dhcpcd -d ${INTERFACE}
exit 0

this is /usr/sbin/netcfg. ive added it to the sudoers file, and made an icon on my desktop. all wifi networks can be set in /etc/wpa_supplicant.conf, no matter WPA, WEP, or unsecure. As long as you understand how to edit your wpa_supplicant.conf file, it will automaticly choose whatever you like.

btw, the option -Bw (daemonize and wait) removes the need for the sleep, as it wont release control untill it finishes. logical AND (&&) is still a good idea though, incase the wpa_supplicant line fails.

you could do far fancier stuff than this, (reporting IP or the like) but since i normally run it from an icon, i dont care to.

_________________
------------------
An OS is a tool. Tools break. Like any good craftsman, I fix my tools. Thus, here I am. :)


 Profile Send private message  
 
 Post subject: Re: script to connect to network
PostPosted: Fri May 18, 2007 7:53 am 
Zenwalk Packager
Zenwalk Packager

Joined: Thu May 25, 2006 9:21 am
Posts: 1788
Location: Portugal
Hi,
here's one of the one's I'm using:
Code:
#!/bin/bash
INTERFACE=wlan0
ESSID=e-U
pid=`pidof wpa_supplicant`
if [ -s $pid ]; then
        kill -9 $pid >/dev/null 2>&1
fi
if [ -f /etc/dhcpc/dhcpcd-${INTERFACE}.pid ]; then
        kill -9 $(cat /etc/dhcpc/dhcpcd-${INTERFACE}.pid) >/dev/null 2>&1
        rm /etc/dhcpc/dhcpcd-${INTERFACE}.pid
fi
iwconfig ${INTERFACE} essid $ESSID
/usr/sbin/wpa_supplicant -Dwext -i${INTERFACE} -c/etc/wpa_supplicant.conf -B
sleep 5
dhcpcd -d ${INTERFACE}


Regards,


 Profile Send private message  
 
 Post subject: Re: script to connect to network
PostPosted: Fri May 18, 2007 1:34 pm 
Regular Zenwalker
Regular Zenwalker

Joined: Thu May 03, 2007 3:44 pm
Posts: 25
The '-Bw' option doesn't work with, I use wpa_supplicant that came with zenwalk and also I don't know how to edit the wpa_supplicant.conf because there is no manual page for that.

Others ways don't do I need also...

I'm doing a script that will parse the output from wpa_supplicant and see in some time if the autentication is successful but it might take a long time to do it.

thanks for the answer you are giving me ideas.


 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


 Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: