Monday, March 5, 2012

Koneksi Wifi Menggunakan wpa_supplicant (Linux)

Pertama buat dulu settingannya di /etc/wpa_supplicant.conf

# cat << EOF >> /etc/wpa_supplicant.conf

> network={

> scan_ssid=1

> ssid="ISIKAN_NAMA_SSIDNYA_DISINI"

> key_mgmt=WPA-PSK

> psk="ISIKAN_PASSWORDNYA_DISINI"

> }

> EOF



Kemudian aktifkan interface wifinya, biasanya di linux menggunakan wlan0 atau eth1.

# ifconfig eth1 up


Jalankan wpa_supplicant sebagai daemon menggunakan konfigurasi tadi.

# wpa_supplicant -B -ieth1 -c/etc/wpa_supplicant.conf


Untuk mendapatkan IP kita bisa menggunakan dhcpcd atau dhclient, disini kita coba menggunakan dhcpcd

# dhcpcd eth1

dhcpcd[6088]: version 5.2.12 starting

dhcpcd[6088]: eth1: broadcasting for a lease

dhcpcd[6088]: eth1: offered 192.168.*.* from 192.168.*.*

dhcpcd[6088]: eth1: ignoring offer of 192.168.*.* from 192.168.*.*

dhcpcd[6088]: eth1: acknowledged 192.168.*.* from 192.168.*.*

dhcpcd[6088]: eth1: checking for 192.168.*.*

dhcpcd[6088]: eth1: leased 192.168.*.* for 86400 seconds

dhcpcd[6088]: forked to background, child pid 6124




Agar internetan lebih cepet, kita bisa setting dns. Biasanya sih saya pake punya google, kita setting nya di /etc/resolv.conf.

# echo -ne "nameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf


Coba cek koneksinya berhasil apa tidak dengan ping ke url mana saja, contoh saya ping ke google

# ping -c 3 www.google.co.id

PING www.l.google.com (74.125.*.*) 56(84) bytes of data.

64 bytes from sin01s05-in-f18.1e100.net (74.125.*.*): icmp_req=1 ttl=54 time=16.1 ms

64 bytes from sin01s05-in-f18.1e100.net (74.125.*.*): icmp_req=2 ttl=54 time=16.4 ms
64 bytes from sin01s05-in-f18.1e100.net (74.125.*.*): icmp_req=3 ttl=54 time=17.1 ms



--- www.l.google.com ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2002ms

rtt min/avg/max/mdev = 16.105/16.539/17.108/0.445 ms




Oh yaa saya sekalian kasih bash scriptnya untuk koneksi manual maupun wpa di linux nih, silahkan di coba sekalian di review :)


function tanya() {
        read -p "Mau static ip ga [y/t] ? " pilih
        if [ $pilih = 'y' ] || [ $pilih = 'Y' ]; then
                read -p ">> Masukkan ip yang anda inginkan: " ip
                read -p ">> Masukkan gateway: " gw
                echo ">> Setting up ip to $ip.. "; ifconfig eth1 $ip/24
                echo ">> Setting up gateway ip to $gw.. "; route add default gw $gw

                if [ $pil = 2 ]; then
                        echo ">> Setting up iwconfig to the ssid.. ";
                        iwconfig $wireless $ssid;
                else
                        echo ">> Setting up wpa supplicant with wpa configuration.. ";
                        wpa_supplicant -B -i $wireless -c /etc/wpa_supplicant.conf;
                fi

        else
                echo ">> Setting up $wireless to $konek "; iwconfig $wireless essid $ssid; echo;
                echo ">> Obtaining ip address.. ";
                dhclient eth1;
        fi
}


clear

echo "##########################################################
##    _____           _____ _______       ___           ##
##    \   \          /   /  |   _  \     /  \           ##
##     \   \        /   /   |  | \  \   / /\ \          ##
##      \   \  /\  /   /    |  |_/  /  / /__\ \         ##
##       \   \/  \/   /     |   ___/  /  ____  \        ##
##        \          /      |  |     /  /    \  \       ##
##         \___/\___/       |__|    /__/      \__\      ##
##########################################################"

echo;
echo -e "\tMenu"
echo "1. WPA"
echo "2. Koneksi Manual";echo;
read -p "Masukkan pilihan anda : " pil
if [ $pil = 1 ]; then
        read -p ">> Nama Interface Device Wireless Anda: " wireless
        echo ">> Getting down $wireless.. "; ifconfig $wireless down;
        echo ">> Changging mac address.. "; macchanger -ar $wireless;
        echo ">> Waking up $wireless.. "; ifconfig $wireless up;
        echo ">> Hasil scan wireless: "; echo; iwlist $wireless scan | grep SSID
        read -p ">> Masukkan SSID yang ingin di koneksikan : " ssid
        read -p ">> Masukkan passwordnya : " pass
        echo ">> Setting up ssid and password to wpa supplicant configuration.. ";
        wpa_passphrase $ssid $pass >> /etc/wpa_supplicant.conf;echo;
        tanya;
else
        read -p ">> Nama Interface Device Wireless Anda: " wireless
        echo ">> Getting down $wireless.. "; ifconfig $wireless down
        echo ">> Changging mac address.. "; macchanger -ar $wireless
        echo ">> Waking up $wireless.. "; ifconfig $wireless up
        echo ">> Hasil scan wireless: "; echo; echo; iwlist $wireless scan | grep SSID
        read -p ">> Masukkan SSID yang ingin anda koneksikan: " ssid; echo
        tanya;
fi

exit 0



Oke selamat mencoba semoga berhasil kawan!

1 comments:

Unknown said...
This comment has been removed by the author.

Post a Comment