Thanks for a lightning fast reply and for a nice link! 
I have been reading and testing for a while now and I got a little further. But I'm still not able to do what I need to:
When i disconnect with the gnome-connection-manager and then try to reconnect with my script, then nothing works.
but: When I don't disconnect from internet with the connection manager, and just run my script, then I'm able to reconnect using my script. I guess that means that my script is functional, but just need some more vital data to be able to connect from scratch?
Here is my connection script so far:
Code:
#!/bin/bash
ifconfig wlan0 down
dhclient -r wlan0
ifconfig wlan0 up
iwconfig wlan0 essid "my network"
iwconfig wlan0 key 10DIGITHEX # s:ASCII_KEY
iwconfig wlan0 key open
#iwconfig wlan0 key restricted ( I try switching between those two without much luck..)
iwconfig wlan0 ap MA:CA:DD:RE:SS:00
iwconfig wlan0 channel 5
iwconfig wlan0 mode Managed
dhclient wlan0
Here is my dmesg | tail:
Code:
[26901.357108] ADDRCONF(NETDEV_UP): wlan0: link is not ready
[26901.396447] wlan0: direct probe to AP MA:CA:DD:RE:SS:00 try 1
[26901.404445] wlan0: direct probe to AP MA:CA:DD:RE:SS:00 try 1
[26901.404476] wlan0 direct probe responded
[26901.404479] wlan0: authenticate with AP MA:CA:DD:RE:SS:00
[26901.407824] wlan0: authenticated
[26901.407827] wlan0: associate with AP MA:CA:DD:RE:SS:00
[26901.409822] wlan0: RX AssocResp from MA:CA:DD:RE:SS:00 (capab=0x431 status=0 aid=7)
[26901.409825] wlan0: associated
[26901.419820] wlan0: disassociating by local choice (reason=3)
Seems that the 'disassociating' from the dmesg is because of timeout, after waiting a long time for dhcp offers.
The output from running script:
Code:
root@syntaxerror:/home/a# sh scriptname
Internet Systems Consortium DHCP Client V3.1.2
Copyright 2004-2008 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/wlan0/MA:CA:DD:RE:SS:00
Sending on LPF/wlan0/MA:CA:DD:RE:SS:00
Sending on Socket/fallback
DHCPRELEASE on wlan0 to 10.0.0.138 port 67
send_packet: Network is unreachable
send_packet: please consult README file regarding broadcast address.
Internet Systems Consortium DHCP Client V3.1.2
Copyright 2004-2008 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/wlan0/MA:CA:DD:RE:SS:00
Sending on LPF/wlan0/MA:CA:DD:RE:SS:00
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 12
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 12
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
No DHCPOFFERS received.
No working leases in persistent database - sleeping.
It would be really nice to understand what fails here.
Bookmarks