configurar a rede wireless passando por roteador (melhorado e comentado)

Publicado por Luiz Cezar 13/11/2005

[ Hits: 7.049 ]

Homepage: infosegura.eti.br

Download wireless.sh




script para configurar sua placa de rede wireless passando por roatedor, agora melhorado e comentado... fique a vontade para fazer melhorias....

  



Esconder cůdigo-fonte

#!/bin/sh

#feito por mestre5 ( www.roxbrasil.com )

# nessa funÁao vc configura todos os parametros e sera executado sem perguntas, usado a opÁao 1 - Automatico
# no menu principal, facilitando as coisas....
Automatico() {
#Definindo as variaveis
modulo='ndiswrapper' #Modulo da placa wireless,††mais do q OBRIGATORIO
interface='wlan0' #Interface do Wireless

# ---- Mostrado usando "iwlist <interface> scan" (como root, sem aspas) -----
AP='00:11:95:0B:F2:90' #MAC do Access Point
ch='7' # Canal usado pra conexao
modo='Managed' # Modo de Acesso ao AP, pode ser: Ad-Hoc, Managed, Master, Repeater, Secondary, Monitor ou Auto
grupo='PORAO' #Nome do ESSID
#----------------------------------------------------------------------------

chavetipo='restricted' #tipo de chave, pode ser: open ou restricted, se naum souber deixe open
chave='d9f43cb298feed65c32cba2942' #Chave secreta, se naum usar deixe em Branco('')
chavenum='3' #Indice da chave WEP, de 1 ŗ 4, se naum souber deixe 1

# ---- Deixe em Branco('') se for usar DHCP ------
ipnum='192.168.2.3' #IP q sera usado
mascara='255.255.255.0' #Mascara usada
gateway='192.168.2.1' #Gateway usado
dns1='24.153.22.67' #DNS Primario
dns2='24.153.23.66' #DNS Secundario
#-------------------------------------------------

printf "Subindo o Modulo... "
if modprobe $modulo; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "ETH0 Down... "
if ifconfig eth0 down; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "WLAN0 Down..."
if ifconfig $interface down; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

if [ $AP != '' ]; then
†††printf "Setando o Mac do Access Point... "
†††if iwconfig $interface ap $AP; then
††††††printf "OK \n"
†††else
††††††printf "Falhou \n"
††††††exit
†††fi
fi

printf "Setando o Channel... "
if iwconfig $interface channel $ch; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "Setando o Modo... "
if iwconfig $interface mode $modo; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

if [ $chave != '' ]; then
†† printf "Setando a Seguranca: \n"
†† printf "†††† Encryptacao... "
†† if iwconfig $interface enc off; then
††††† printf "OK \n"
†† else
††††† printf "Falhou \n"
††††† exit
†† fi
†† printf "†††† Chave Wep... "
†† if iwconfig $interface key $chavetipo [$chavenum] $chave; then
†† †††iwconfig $interface key [$chavenum] #Ativa a chave escolhida
††††† printf "OK \n"
†† else
††††† printf "Falhou \n"
††††† exit
†† fi
fi

printf "Setando o ESSID... "
if iwconfig $interface essid $grupo; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "WLAN0 Up... "
if ifconfig $interface up; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

#Se for DHCP vai pra funcao DHCP
if [ "$ipnum" = "" ]; then
†††dhcp
fi 

printf "Definindo o IP e Mascara... "
if ifconfig $interface $ipnum netmask $mascara; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "Configurando a Rota: \n"
#route del default
printf "†††† Rota padrao... "
if route add default $interface; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi
printf "†††† Definindo Gateway... "
if route add default gw $gateway; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "Setando o Nameserver... "
echo nameserver $dns1 > /etc/resolv.conf
if echo nameserver $dns2 >> /etc/resolv.conf; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi
}

ipmanual() {
printf "Qual o IP Local? EX: 192.168.0.2\n"
printf "=> "
read ipnum
printf "Qual a mascara? EX: 255.255.255.0\n"
printf "=> "
read mascara
printf "Qual o IP do Gateway? EX: 192.168.0.1\n"
printf "=> "
read ipgat
printf "Qual o IP do DNS? EX: 200.204.10.38\n"
printf "=> "
read ipdns
}

dhcp() {
printf "$interface Up... "
if ifconfig $interface up; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

if which dhcpcd; then
†† dhcpcd $interface
elif which dhclient; then
†† dhclient $interface
else
†† printf "Instale o DHCPCD ou DHCLIENT e rode o script novamente..."
†† exit
fi

testando
exit
}

Manual() {
clear

printf "Qual o modulo da Placa? EX: ndiswrapper \n"
printf "=> "
read modulo
if [ "$modulo" = "" ]; then
†††clear
†††printf "O Modulo eh mais do q OBRIGATORIO..."
†††printf "\n"
†††Manual
fi
printf "Subindo o Modulo... "
if modprobe $modulo; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

#escolhendo a interface
iwconfig
printf "\n Qual eh a sua interface? EX: wlan0 \n"
printf "=> "
read interface
if [ "$interface" = "" ]; then
†††$interface='wlan0'
fi

#Verificando as redes disponiveis
clear
iwlist $interface scan
printf " \n"

printf "Qual o MAC do Access Point? EX: 00:11:95:0B:F2:90\n"
printf "Deixe em branco c naum souber\n"
printf "=> "
read ap

printf "Qual o Channel? EX: 11\n"
printf "=> "
read channel
if [ "$channel" = "" ]; then
†† clear
†† printf "O Channel eh Obrigatorio"
†† exit
fi

printf "Qual o Modo? EX: Managed\n"
printf "=> "
read modo
if [ "$modo" = "" ]; then
†† clear
†† printf "O Modo eh Obrigatorio"
†† exit
fi

printf "Qual a chave Wep? EX: 4CFC38ACE530B3E9EBFAD50453\n"
printf "Deixe em branco c naum Usar\n"
printf "=> "
read wep
if [ $wep != '' ]; then
†† printf "Qual o modo de Encrytacao?\n"
†† printf "1 - Open\n"
†† printf "2 - Restricted\n"
†† printf "=> "
†† read tipowep
†† case $tipowep in
†† †††1) $tipowep='open' ;;
†† †††2) $tipowep='restricted' ;;
†† †††*) $tipowep='open' ;;
†††esac
†††printf "Qual o indice da chave WEP? *se naum souber use 1 ...\n"
†† printf "1 - um\n"
†† printf "2 - dois\n"
†† printf "3 - tres\n"
†† printf "4 - quatro\n"
†† printf "=> "
†† read chavenum
†† case $chavenum in
†† †††1) $chavenum='1' ;;
†† †††2) $chavenum='2' ;;
†† †††3) $chavenum='3' ;;
†† †††4) $chavenum='4' ;;
†† †††*) $chavenum='1' ;;
†††esac
fi

printf "Qual a chave ESSID? EX: default\n"
printf "=> "
read essid
if [ "$essid" = "" ]; then
†† clear
†† printf "O ESSID eh Obrigatorio"
†† exit
fi

printf "Definir o IP ou usar DHCP?\n"
printf "1 - Definir Manualmente \n"
printf "2 - DHCP \n"
printf "=> "
read ip

case $ip in
†† 1) ipmanual ;;
†† 2) dhcp ;;
esac

#*********** Subindo a configuraÁ„o setada **************
printf "ETH0 Down... "
if ifconfig eth0 down; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "$interface Down..."
if ifconfig $interface down; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

if [ $ap != '' ]; then
†† printf "Setando o Mac do Access Point... "
†† if iwconfig $interface ap $ap; then
††††† printf "OK \n"
†† else
††††† printf "Falhou \n"
††††† exit
†††fi
fi

printf "Setando o Channel... "
if iwconfig $interface channel $channel; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "Setando o Modo... "
if iwconfig $interface mode $modo; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

if [ $wep != '' ]; then
†† printf "Setando a Seguranca: \n"
†† printf "†††† Encryptacao... "
†† if iwconfig $interface enc off; then
††††† printf "OK \n"
†† else
††††† printf "Falhou \n"
††††† exit
†† fi
†† printf "†††† Chave Wep... "
†† if iwconfig $interface key $tipowep [$chavenum] $wep; then
†† †††iwconfig $interface key [$chavenum]
††††† printf "OK \n"
†† else
††††† printf "Falhou \n"
††††† exit
†† fi
fi

printf "Setando o ESSID... "
if iwconfig $interface essid $essid; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "WLAN0 Up... "
if ifconfig $interface up; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "Definindo o IP e Mascara... "
if ifconfig $interface $ipnum netmask $mascara; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "Configurando a Rota: \n"
#route del default
printf "†††† Rota padrao... "
if route add default $interface; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "†††† Definindo Gateway... "
if route add default gw $ipgat; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi

printf "Setando o Nameserver(DNS)... "
if echo nameserver $ipdns > /etc/resolv.conf; then
†††printf "OK \n"
else
†††printf "Falhou \n"
†††exit
fi
}

testando() {
iwconfig $interface
ifconfig $interface
#route
if ping -c2 www.terra.com.br; then
†††printf "INTERNET UP... \n"
else
†††printf "Internet Down...\n"
fi
}

#=== Principal====
clear

printf "1 - Automatico \n"
printf "2 - Manual \n"
printf "=> "
read opcao

case $opcao in
†† 1) Automatico ;;
†† 2) Manual ;;
†† *) exit ;;
esac

testando

Scripts recomendados

Barra de progresso

Twitter via linha de comando!

Instalador de Cůdigo Fonte

Reativando Placa Wifi

ORACLE 10.2g - Fazendo Restore


  

ComentŠrios

Nenhum comentŠrio foi encontrado.


Contribuir com comentŠrio