wpa supplicant

wifi:
The most commonly used tools are wireless-tools & wpa_supplicant. wpa_supplicant serves as daemon, wpa_cli serves as client.

1. wpa_supplicant.conf

update_config=1
ctrl_interface=socket_dir
eapol_version=1
ap_scan=1
fast_reauth=1

2. start daemon

wpa_supplicant -Dnl80211 -iwlan0 -c wpa_supplicant.conf -d
  -D: driver
  -d: debug
  -c: config file

3. run client

wpa_cli -i wlan0 -p socket_dir/
  >scan
  >scan_results
  >add_network
  >set_network 0 ssid "NTGR-2.4G"

  ---WPA-PSK/WPA2-PSK
  >set_network 0 psk ""
  ---OPEN
  >set_network 0 key_mgmt NONE
  ---WEP
  >set_network 0 key_mgmt NONE
  >set_network 0 wep_key0 "the_pwd"

  >select_network 0
  >enable_network 0
  >list_networks
  >status
  >save_config
  >quit

4. get IP

dhclient wlan0

5. do anything u want

6. stop wpa_supplicant in wpa_cli

>terminate

7. final wpa_supplicant.conf

ctrl_interface=socket_dir
update_config=1

network={
     ssid="NTGR-2.4G"
     psk="12345678"
}