Logo Webdesign, Anwendungsentwicklung, Linux-Kickstart

Postalisch

ODT Export PDF Export

My-IP6-Tool

This script is a powerfull, but at the moment very specialized, tool to dis/connect to IPv6 Networks with a wireless connection. It also could do pings and stores some IPv6 Adresses (which are hard to remember). I try to clean the specialised parts out later. This script is mainly developed by Ralf and I did only some fixes for the openMoko and cosmetics.

my-ip6-tool.sh

#!/bin/bash
#
# FH Koeln
# WPF-IPv6 und IPSec für IPv6
#
# Ralf Beckesch
# Manuel Krischer
#
# Tool zur Client-Verbindung im IPv6 Testnetzes
 
PROGNAME=$(basename $0)
RESOLVCONF=/etc/resolv.conf
IPV6DNS="2001:470:9b60:1:204:75ff:feca:d983"
PC1a=2001:470:9b60:1:204:75ff:feca:d983
PC1b=2001:470:9b60:2:204:75ff:fe74:b81a
PC2=2001:470:9b60:1:204:75ff:feca:ccc7
PC3=2001:470:9b60:2:204:75ff:feca:d967
PC4=2001:470:9b60:2:204:75ff:feca:d854
OM1=2001:470:9b60:1:212:cfff:fe4a:c258
OM2=2001:470:9b60:2:212:cfff:fe4a:c258
R2H1=2001:470:9b60:1:21a:92ff:fef0:e9ad
R2H2=2001:470:9b60:2:21a:92ff:fef0:e9ad
MINI1=2001:470:9b60:1:223:8ff:fe2c:3652
MINI2=2001:470:9b60:2:223:8ff:fe2c:3652
 
DNS=$IPV6DNS
ALL_CLIENTS="PC1a PC1b PC2 PC3 PC4 DNS OM1 OM2 R2H1 R2H2 MINI1 MINI2"
IPV6DOM="ktds6"
 
DEV_OM=om-gta02
DEV_R2H=ktds-laptop
DEV_MINI=minimi
 
NW_DEV_OM=eth0
NW_DEV_R2H=wlan0
NW_DEV_MINI=eth1
 
STATUS=/proc/net/wireless
 
NETZE="[ AR | HA ]"
 
error () {
    echo -e "\033[01;31m$*\033[00m"
}
 
print () {
    echo -e "$*" >&1
}
 
verbose () {
    if [ -n "$VERBOSE" ]; then
        print $*
    fi
}
 
debug () {
    if [ -n "$DEBUG" ]; then
        print '\033[01;36m'debug:'\033[00m' $*
    fi
}
 
error_exit ()
{
    error $*
    exit 1
}
 
help ()
{
    print "\n\t$PROGNAME - Schweizer IPv6 Taschenkettensaege\n"
    print "--help | -h"
    print "\tDatt hier!"
    print "--list | -l"
    print "\tAlle sichtbaren WLAN SSIDS anzeigen"
    print "--connect | -c | connect | con $NETZE"
    print "\tmit gewähltem Netzwerk verbinden"
    print "--disconnect | -d | dcon"
    print "\tVerbindung mit Netz lösen"
    print "--resolv | -R "
    print "\tresolv.conf auf IPv6 Nameserver setzen"
    print "--status | -s | stat | status"
    print "\tVerbindungsstatus anzeigen"
    print "--ping | -p | p"
    print "\tAlle ($ALL_CLIENTS) Hosts einmal anpingen "
    print "--debug | -D | debug"
    print "\tDebug-Modus einschalten"
}
 
cur_ipv6 () {
    echo "$(ifconfig $NWDEV | grep -i inet6-adresse | head -1 | awk '{print $2}')"
}
 
cur_ssid () {
    echo "$(iwconfig $NWDEV | grep IEEE | sed 's/.*ESSID://g' | sed 's/"//g'| sed 's/ *$//g')"
}
 
status (){
    print Lokale IPv6
    print "\t'$( cur_ipv6 )'"
    print SSID
    print "\t'$( cur_ssid )'"
 
}
 
sping () {
    po=$(ping6 -c 1 $1 2>&1)
    R=$?
    if [ "$R" != "0" ]; then
        echo -en "\033[01;31mFehler: Gerät nicht erreichbar\033[00m"
    else
        echo -en "\033[01;32mOK Gerät antwortet\033[00m"
    fi
}
 
ping_all () {
        echo "Pingtest"
    for host in $ALL_CLIENTS; do
        echo -e "$host : "
        eval tmp=\${$host}
        echo -e "\tIPv6:\t$tmp"
        echo -en "\tstat:\t"
        sping $tmp
        echo
    done
}
 
r2h_dev_reload () {
    if [ "$DEVNAME" == "AsusR2H" ]; then
        debug r2h_dev_reload
        debug ifconfig $NWDEV down
        ifconfig $NWDEV down
        debug rmmod zd1211rw
        rmmod zd1211rw
        debug modprobe zd1211rw
        modprobe zd1211rw
        debug ifconfig $NWDEV up
        ifconfig $NWDEV up
    fi
}
 
disconnect () {
    debug "disconnect() ip link set $NWDEV down"
    ip link set $NWDEV down
    if [ "$DEVNAME" != "OpenMoko" ]; then
        debug "disconnect() iwconfig essid \"\""
        iwconfig $NWDEV essid ""
    else
        debug iwconfig NICHT ausgefuehrt
    fi
    r2h_dev_reload
}
 
show () {
    local c=$1
    debug "show() Netzwerk: $c"
    local iwo
    local ifo
    eval iwo=\${IW_OPTS_$c}
    eval ifo=\${IF_OPTS_$c}
    print Parameter für Netzwerk $c
    print iwconfig:
    print "\t$iwo"
    print ip:
    print "\t$ifo"
 
}
 
connect () {
    local c=$1
    debug "connect() Netzwerk: $c"
    r2h_dev_reload
    local iwo
    local ifo
    eval iwo=\${IW_OPTS_$c}
    eval ifo=\${IF_OPTS_$c}
    if [ -z "$iwo" -o -z "$ifo" ]; then
        error_exit Netzwerk $c existiert nicht
    fi
#    debug iwo: $iwo
#    debug ifo: $ifo
    iwconfig $iwo
    debug "connect() iwconfig $iwo"
    ip $ifo
    debug "connect() ip $ifo"
}
 
if [ "$UID" != "0" ]; then
    error_exit "Bitte als Root ausführen!"
fi
 
if [ "$(hostname)" == "$DEV_OM" ]; then
    print "OpenMoko erkannt"
    NWDEV=$NW_DEV_OM
    DEVNAME=OpenMoko
fi
 
if [ "$(hostname)" == "$DEV_R2H" ]; then
    print "Asus R2H erkannt"
    NWDEV=$NW_DEV_R2H
    DEVNAME="AsusR2H"
fi
 
if [ "$(hostname)" == "$DEV_MINI" ]; then
        print "Dell Mini 9 erkannt"
        NWDEV=$NW_DEV_MINI
        DEVNAME="DellMini"
fi
 
 
 
if [ -z "$DEVNAME" ]; then
    error "G e r ä t  n i c h t  e r k a n n t !!!"
    NWDEV=wlan0
fi
 
IW_OPTS_HA="$NWDEV mode Managed essid ipv6_ap250 channel 7"
IF_OPTS_HA="link set $NWDEV up"
 
IW_OPTS_AR="$NWDEV mode Managed essid ipv6_ap251 channel 7"
IF_OPTS_AR="link set $NWDEV up"
 
while [ -n "$1" ]; do
 
    debug futtere paramter "$1"
 
    case "$1" in
 
    --debug|-D|debug)
        DEBUG=JAWOHL
        debug eingeschaltet
    ;;
    --ping|-p|p)
        ping_all
        exit 0
        ;;
    --list|-l|list)
        for i in $(iwlist $NWDEV scanning | grep ESSID | sed 's/ESSID:\|"//g'); do
            echo $i
        done
        exit 0
        ;;
 
    --connect|-c|con)
        shift
        if [ -n "$1" ]; then
            connect $1
            exit 0
        else
            error_exit Parameter für --connect erwartet
        fi
        ;;
    --disconnect|-d|dcon)
        disconnect
        exit 0
        ;;
    --resolv|-R|res|resolv)
        debug DNS auf \"$IPV6DNS\" gesetzt
        debug Suchdomäne ist: $IPV6DOM
        echo -n > $RESOLVCONF
        echo "nameserver $IPV6DNS"    >> $RESOLVCONF
        echo "domain $IPV6DOM"        >> $RESOLVCONF
        exit 0
        ;;
    --status|-s|stat|status)
        status
        exit 0
        ;;
    --help|-h|help)
        help
        exit 0
        ;;
    *)
        help
        echo -e "\n\n\tParamter \"$1\" nicht erkannt"
        ;;
    esac
    shift
done
print "Was soll ich machen, frag mich mit $PROGNAME --help"
exit 0
 
linux/special/my-ip6-tool.txt · Zuletzt geändert: 2010/12/10 01:14 (Externe Bearbeitung)
Pragmatisch für Ihre Freiheit!