You are not logged in.
Hello,
I'm using iwconfig to connect to my wireless nework:
ip link set dev ra0 down
ip addr flush dev ra0
ip route flush dev ra0
iwconfig ra0 essid MyNetwork
iwconfig ra0 key MyPassword
ip link set dev ra0 up
ip addr add 192.168.1.100/24 broadcast 192.168.1.255 dev ra0
ip route add default via 192.168.1.1
The problem with this is, when signal is lost iwconfig doesn't reconnect automatically.
So I wrote this script running in background to keep the connection alive, that is, to keep reconnecting until signal is re-established:
#!/bin/bash
interface="ra0"
essid="$(iwgetid -r)"
if [ "$essid" == "" ]
then
echo "ESSID could not be read."
exit 0
fi
echo "Loop started for ESSID: $essid"
while true
do
if [ "$(cat /sys/class/net/$interface/carrier)" == "0" ]
then
iwconfig ra0 essid $essid
echo "$(date): Attempted reconnect to $essid."
fi
sleep 1
done
but I was hoping for cleaner solution, maybe something integrated in iwconfig or iw... does something like that exist?
Thanks.
Last edited by karabaja4 (2014-12-28 23:20:06)
Offline
This is what network management tools were made for... Is there a reason why you are trying to avoid that?
Offline
This is what network management tools were made for... Is there a reason why you are trying to avoid that?
No real reason, I just feel more comfortable doing things myself... for example I hate when network management tools start wpa_supplicant, dhcpcd or something else that is out of my control.
Is there a tool which would NOT start any of the (above mentioned) network daemons and NOT assign any IP addresses, just authenticate with AP and reconnect if dropped?
Offline
As already indicated, iwconfig will not do this. This what I see as one of the *good* things about tools like iwconfig: it does it's job, then it shuts down. But if you want to monitor the status of the connection and reconnect, then you do need a daemonized process - you need something lurking in the background watching the connection.
As WW mentioned, this is one of the many obnoxious and intrusive things that the big network management suites do. But if you want only this one feature and not all the other stuff they include, then your approach looks just right to me. If it works, use it - what would you want "cleaner"? I always prefer to write such things in C myself - there is no real practical use, but it's a good learning opportunity and just 'feels' cleaner for my mild OCD. I ended up writing a wifi tool in C, and included this sort of reconnect option when someone requested it - but I never use the reconnect option and plan on removing it soon (I just find the code to be to ugly to live). But if you want to get ideas, feel free to check it out:
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
So you want reactions to state changes without using something that keeps track of state, i.e. a daemon. That's... yeah.
You won't get around using something that's supposedly "out of your control". No complex full-fledged network manager is needed though, wpa_supplicant alone will do.
This what I see as one of the *good* things about tools like iwconfig: it does it's job, then it shuts down.
Yeah, but that's why iwconfig will never be capable of WPA. Because WPA isn't a fire-and-forget thing, it's much more involved than that. WEP is fire-and-forget, but that's why WEP is such crap security-wise.
Last edited by Gusar (2014-12-28 23:23:46)
Offline
Thanks for the input Marking as solved.
Offline
Yeah, but that's why iwconfig will never be capable of WPA
True, but that doesn't seem relevant. We're not talking about wpa networks here. iwconfig is only for connecting to open networks (or maybe WEP, but they may as well be open). With an open network, a daemonized process is not needed.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
True, but that doesn't seem relevant. We're not talking about wpa networks here.
Yep, which could be a discussion of it's own though , why is karabaja4 running a WEP network?
What I was getting at is that fire-and-forget is not always good, so sticking to it just because it's "simple" is not always the correct way to go. In this case, it seems karabaja4 would rather run a shell instance (a big shell even) that calls out to external binaries (cat, iwconfig, sleep) every second than use wpa_supplicant, which would do the job more efficiently (contrary to its name, wpa_supplicant can handle WEP networks too).
Last edited by Gusar (2014-12-29 00:00:32)
Offline