wlan und routening

Einrichten des lokalen Netzes, Verbindung zu anderen Computern und Diensten.
Antworten
Benutzeravatar
Voyager_MP
Beiträge: 628
Registriert: 22.06.2004 10:04:07
Wohnort: Aachen

wlan und routening

Beitrag von Voyager_MP » 24.06.2004 16:53:38

Hier ein kleines script, welches für laptops gedacht ist, und beim systemstart (rcS)
gestartet werden soll um zu proben welche netzwerke verfügbar sind und dann automatsch conneted.

leider bekomme ich das routeing nicht so perfekt hin. wenn jemand helfen will, gerne.

Bin für verbesserungen gerne offen

#!/bin/bash
#export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
###############################
# Written by Michel Pelzer
# Company ATecoM GmbH
# last modified at 22.06.2004
###############################

red='\e[0;31m'
green='\e[1;32m'
nc='\e[0m'

###############################
# Edit only the following lines
###############################

DEVICE_LAN='eth0'
DEVICE_WLAN0='wlan0'
DEVICE_WLAN1='wlan1'

# Office Wlan
###############################
officenet='""'
officeip=''
officegw=''
officeessid=''
officenickname=''
officekey=''
officebcast=''
officedns=''
officednsprafix=''
officeprintcap=''

# Home Wlan
###############################
homenet='""'
homeip=''
homegw=''
homebcast=''
homekey=''
homeessid=''
homenickname=''
homedns=''
homednsprafix=''
homeprintcap=''

# Other free to air net
###############################
othernet='"Free-to-air"'
othernetnickname='Voyager_MP'

# Do not edit any further !
##################################################################################
#ifconfig lo up >/dev/null 2>&1
#ifconfig eth0 1.1.1.1 netmask 0.0.0.0 up
#sleep 5

which iwconfig >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo >/dev/null
else
echo "iwconfig is missing"
echo
echo "Please fetch wireless-tools"
echo "---------------------------"
echo
fi

which ethtool >/dev/null 2>&1

RESULT=$?
if [ $RESULT -eq 0 ]; then
echo > /dev/null
else
echo "ethtool is missing"
echo
echo "Please fetch Ethtool from"
echo "http://sourceforge.net/projects/gkernel"
echo "---------------------------------------"
echo
fi

ethtool $DEVICE_LAN | grep Link | grep yes >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -e "Status for $DEVICE_LAN: ${green}Link${nc} "
echo "---------------------"
echo -e -n "Connecting to $officenet on Device $DEVICE_LAN ... "
ifconfig $DEVICE_WLAN0 down >/dev/null 2>&1
ifconfig $DEVICE_WLAN1 down >/dev/null 2>&1
ifconfig $DEVICE_LAN $officeip netmask 255.255.255.0 broadcast $officebcast up
ping -c 1 $officegw >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
route add default gw $officegw >/dev/null 2>&1
echo "search $officednsprafix" >/etc/resolv.conf
echo "nameserver $officedns">>/etc/resolv.conf
echo -e ${green} "done" ${nc}
cp -rf /etc/printcap.office /etc/printcap >/dev/null 2>&1
/etc/init.d/lprng reload >/dev/null 2>&1
exit 0
else
echo -e ${red} "failed" ${nc}
echo -n "Connecting to $homenet on Device $DEVICE_LAN ... "
ifconfig $DEVICE_WLAN0 down >/dev/null 2>&1
ifconfig $DEVICE_WLAN1 down >/dev/null 2>&1
ifconfig $DEVICE_LAN $homeip netmask 255.255.255.0 broadcast $homebcast
ping -c 1 $homegw >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
route add default gw $homegw >/dev/null 2>&1
echo "search $homednsprafix" >/etc/resolv.conf
echo "nameserver $homedns">>/etc/resolv.conf
echo -e ${green} \\t "done" ${nc}
cp -rf /etc/printcap.home /etc/printcap >/dev/null 2>&1
/etc/init.d/lprng reload >/dev/null 2>&1
exit 0
else
echo -e ${red} \\t "failed" ${nc}
echo -n "Connecting via DHCP to any reachable Network on Device $DEVICE_LAN ... "
ifconfig $DEVICE_WLAN0 down >/dev/null 2>&1
ifconfig $DEVICE_WLAN1 down >/dev/null 2>&1
dhclient $DEVICE_LAN >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -e ${green} \\t "done" ${nc}
exit 0
else
echo -e ${red} \\t "failed" ${nc}
fi
fi
fi
else
echo -e "Status for $DEVICE_LAN: ${red}No link${nc}"
cat /proc/net/wireless | grep "$DEVICE_WLAN1" >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -e "Status for $DEVICE_WLAN1: ${green}Link${nc}"
echo "---------------------"
INTERFACE=$DEVICE_WLAN1
else
cat /proc/net/wireless | grep "$DEVICE_WLAN0" >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -e "Status for $DEVICE_WLAN0: ${green}Link${nc}"
echo "---------------------"
INTERFACE=$DEVICE_WLAN0
echo "`date` Trying to connect to Wireless Network $officenet on device $INTERFACE" >>/var/log/syslog
echo -e -n "Connecting to Wireless Network $officenet on device $INTERFACE ... "
iwlist $INTERFACE scan | grep $officeessid >/dev/null
RESULT=$?
if [ $RESULT -eq 0 ]; then
iwconfig $INTERFACE essid $officeessid nickname $officenickname key $officekey
ifconfig $DEVICE_LAN down >/dev/null 2>&1
dhclient $INTERFACE >/dev/null 2>&1
ping -c 1 $officegw >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
cp -rf $officeprintcap /etc/printcap >/dev/null 2>&1
/etc/init.d/lprng reload >/dev/null 2>&1
echo -e ${green} "done" ${nc}
exit 0
else
echo -e ${red} "failed" ${nc}
fi
else
echo -e ${red}"Failed"${nc}
fi
echo "`date`Trying to connect to Wireless Network $homenet on Device $INTERFACE" >>/var/log/syslog
echo -e -n "Connecting to Wireless Network $homenet on device $INTERFACE ... "
iwlist $INTERFACE scan | grep $homeessid >/dev/null
RESULT=$?
if [ $RESULT -eq 0 ]; then
iwconfig $INTERFACE essid $homeessid nickname $homenickname key $homekey
ifconfig $DEVICE_LAN down >/dev/null 2>&1
dhclient $INTERFACE >/dev/null 2>&1
ping -c 1 $homegw >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
cp -rf $homeprintcap /etc/printcap >/dev/null 2>&1
/etc/init.d/lprng reload >/dev/null 2>&1
echo -e ${green} "done" ${nc}
exit 0
else
echo -e ${red} "failed" ${nc}
fi
else
echo -e ${red}"Failed"${nc}
fi
iwconfig $INTERFACE essid any nickname $othernetnickname
echo "`date`Trying to connect to Wireless Network $othernet on Device $INTERFACE" >>/var/log/syslog
echo -e -n "Connecting to Wireless Network $othernet on device $INTERFACE ... "
ifconfig $DEVICE_LAN down >/dev/null 2>&1
dhclient $INTERFACE >/dev/null 2>&1
ping -c 1 sun.de >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -e ${green} "done" ${nc}
exit 0
else
echo -e ${red}"failed" ${nc}
echo
fi

else
echo -e "Status for $DEVICE_WLAN0: ${red}No Link${nc}"
fi
echo -e "Status for $DEVICE_WLAN1: ${red}No Link${nc}"
echo
echo -e ${red}"Sorry, no network REACHED !!!"${nc}
echo -e ${red}"-----------------------------"${nc}
fi
fi
echo

Antworten