Code: Alles auswählen
#!/bin/bash
#===================================================================================
#
# FILE: NETWORK1.sh
#
# USAGE: ./network.sh
#
# SYNOPSIS:
#
# DESCRIPTION:
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Michel Pelzer (),
# COMPANY: ATecoM GmbH
# VERSION: 1.0
# CREATED: 21.08.2004 11:26:20 CEST
# REVISION: ---
#===================================================================================
#DEVICES
DRIVER="ndiswrapper"
NICKNAME="Michel"
#COLOURS
CS="\\033[1;32m"
CF="\\033[1;31m"
CN="\\033[0;39m"
# LAN
####################################################################################
lantest () {
DEVICE=`ifconfig | grep eth0 | gawk 'NR == 1 {print $1}'`
if [ -z $DEVICE ]; then
#echo "setze test lan auf"
ifconfig eth0 1.1.1.1 netmask 0.0.0.0 up
sleep 4
fi
LINKSTATUS=`ethtool eth0 |grep Link | gawk '{print $3}' | sed -e 's,[:],,g'`
if [ $LINKSTATUS == "yes" ]; then
echo -e $CS"found"$CN
else
ifconfig eth0 down
echo -e $CF"not found"$CN
fi
}
echo -en "Network: Checking for Cabel: "
lantest
echo -e "Network: Negotiating with Network: Please wait ..."
case $LINKSTATUS in
yes)
WLAN=`cat /proc/net/wireless | grep wlan* | gawk '{print $1}' | sed -e 's,[:],,g'`
ifconfig $WLAN down >/dev/null 2>&1
dhclient eth0 >/dev/null 2>&1
RESULT=`ifconfig | grep -n2 eth0 | gawk 'NR == 2 {print $2}'`
if [ $RESULT = "inet" ]; then
GATEWAY=`route -n | grep eth0 | grep -v 255.* | gawk '{print $2}'`
ping -c 1 $GATEWAY >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -en "Network: Connection Established with " $CS
case $GATEWAY in
10.2.4.1)
echo "atecom"
ln -sf /etc/printcap.office /etc/printcap
/etc/init.d/lprng reload >/dev/null 2>&1
;;
192.168.120.1)
echo "pelzernet"
ln -sf /etc/printcap.home /etc/printcap
/etc/init.d/lprng reload >/dev/null 2>&1
;;
*)
echo "unknown"
;;
esac
fi
fi
echo -e $CN
;;
no)
# Wlan
####################################################################################
wlanscan () {
WLAN=`cat /proc/net/wireless | grep wlan* | gawk '{print $1}' | sed -e 's,[:],,g'`
if [ -z $WLAN ]; then
# echo "lade treiber"
modprobe $DRIVER
sleep 4
fi
ESSID=`iwlist $WLAN scan | gawk 'NR == 3 {print $1}' | sed -e 's,["],,g' -e 's,[ESSID:],,g'`
}
wlanscan
gateway () {
GATEWAY=`route -n | grep $WLAN | grep -v 255.* | gawk '{print $2}'`
}
connect () {
iwconfig $WLAN essid $ESSID nickname $NICKNAME $KEY
dhclient $WLAN >/dev/null 2>&1
RESULT=`ifconfig | grep -n2 $WLAN | gawk 'NR == 4 {print $2}'`
if [ $RESULT = "inet" ]; then
gateway
ping -c 1 $GATEWAY >/dev/null 2>&1
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo -e "Network: Connection established with" $CS\"$ESSID\"$CN
else
echo -e "Network: Failed to connect to" $CS\"$ESSID\"$CN
fi
fi
}
case $ESSID in
pelzernet)
KEY="key "
connect
ln -sf /etc/printcap.home /etc/printcap
/etc/init.d/lprng reload >/dev/null 2>&1
;;
atecom)
KEY="key "
connect
ln -sf /etc/printcap.office /etc/printcap
/etc/init.d/lprng reload >/dev/null 2>&1
;;
lettow)
KEY="key "
connect
;;
*)
NICKAME="Voyager_MP"
;;
esac
esac
Ich benutze es, um mein laptop in wechselnden umgebungen automatisch an Netz anzubinden.
Bin für jegliche verbesserungen offen, Programme wie netenv oder so passten irgendwie nicht, somit hab ich mir gedacht, das es wohl das beste wäre sowas selber zu basten...
Vielleicht entwickelt sich ja ein neues Projekt daraus.