Connect to WEP Wireless Network by command line on Ubuntu

I am a newbie to both network and Linux. I am now trying to connect to a WEP wireless network by command line on my Ubuntu 8.10, because the Network Manager does not support 64 bit WEP.

(1) I firstly bring down the Network Manager and then try to connect to a wireless network, whose essid is candy and password is 5673212741. But it fails as shown in the following. The signal is not very strong, but I can connect to it in Windows 7. I wonder why and how to do it correctly for Ubuntu?

$ sudo /etc/init.d/NetworkManager stop  
 * Stopping network connection manager NetworkManager        [ OK ]   
$ sudo iwconfig wlan0 essid candy  
 opendo iwconfig wlan0 key 18018ce78e open  
$ sudo iwconfig wlan0 key 5673212741 open   
$ sudo  dhclient wlan0  
There is already a pid file /var/run/dhclient.pid with pid 9971  
killed old client process, removed PID file  
Internet Systems Consortium DHCP Client V3.1.1  
Copyright 2004-2008 Internet Systems Consortium.  
All rights reserved.  
For info, please visit http://www.isc.org/sw/dhcp/  

wmaster0: unknown hardware address type 801  
wmaster0: unknown hardware address type 801  
Listening on LPF/wlan0/00:0e:9b:cd:4e:18  
Sending on   LPF/wlan0/00:0e:9b:cd:4e:18  
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 12  
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 20  
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 13  
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 9  
No DHCPOFFERS received.  
No working leases in persistent database - sleeping.  
$ ping www.bbc.co.uk  
ping: unknown host www.bbc.co.uk

(2) A less important question: why the scan for wireless networ does not work after I bring down the Network Manager?

$ sudo /etc/init.d/NetworkManager stop  
 * Stopping network connection manager NetworkManager         [ OK ]   
$ sudo iwlist wlan0 scan  
wlan0     Interface doesn't support scanning : Network is down      

Thanks and regards!


sudo /sbin/ifconfig wlan0 up
sudo /sbin/iwlist wlan0 scan
sudo /sbin/iwconfig wlan0 essid "candy"
sudo /sbin/iwconfig wlan0 key 4104672851
sudo /sbin/iwconfig wlan0 enc on

then check using sudo /sbin/iwconfig wlan0 to make sure it looks configured, then sudo dhclient wlan0

2) scanning fails because bringing down Network Manager brings the interface wlan0 down. sudo /sbin/ifconfig wlan0 up will re-enable scanning.