Deprecated: Assigning the return value of new by reference is deprecated in /home/www/web535/html/dokuwiki/inc/parserutils.php on line 202

Deprecated: Assigning the return value of new by reference is deprecated in /home/www/web535/html/dokuwiki/inc/parserutils.php on line 205

Deprecated: Assigning the return value of new by reference is deprecated in /home/www/web535/html/dokuwiki/inc/parserutils.php on line 314

Deprecated: Assigning the return value of new by reference is deprecated in /home/www/web535/html/dokuwiki/inc/parserutils.php on line 454

Deprecated: Function split() is deprecated in /home/www/web535/html/dokuwiki/inc/auth.php on line 146

Warning: Cannot modify header information - headers already sent by (output started at /home/www/web535/html/dokuwiki/inc/parserutils.php:202) in /home/www/web535/html/dokuwiki/inc/auth.php on line 236

Warning: Cannot modify header information - headers already sent by (output started at /home/www/web535/html/dokuwiki/inc/parserutils.php:202) in /home/www/web535/html/dokuwiki/inc/actions.php on line 128
linux_scripts:linux_network.sh [wiki.BerndLux.de]
 

network.sh

Ein Script um schnell und comfortabel die Netzwerkeinstellungen unter Linux auf meinem Laptop zu Àndern. Wenn man einwenig von shellscripting versteht kann man sich das Script schnell an eigenen gegebenheiten anpassen. Da das Script aber aus der praktischen Anwendug stammt ist es in fortwÀhrender entwiklung und verÀndert sich stÀndig, es EndhÀlt desshalb auch Teile die nicht fertig Entwikelt sind, oder schlich weg garnicht funktionieren. Ich hoffe aber das es dennoch fÌr einige Anregung und Beispiel ist.

Bernd 2005/12/05 07:49

 #!/bin/bash
 
 #==============================================================================
 # VERSION : 0.0.3
 # LICENCE : GPL
 # PURPOSE : switch different networks on my laptop 
 # DATE    : 2005-10-10 18:40 
 # REVISION: 2005-10-05 19:34
 # AUTHOR  : (c) 05.10.05  Bernd Luxenburger, bernd@rlux.de
 # ORIGINAL: (c) 04.01.17 Bernd Luxenburger, bernd@rlux.de
 # USAGE   :  switch different networks on my laptop 
 # USES    :  a lot of standart network tools 
 # SW      : bash, network tools
 # SYSTEM  : GNU/LINUX 
 # INIFILE :  
 # =============================================================================
 # CANGELOG:
 # 04.06.19 19:12 v.0.0.1 ------
 #  + adhoc
 #  + tidy up a bit
 #  + test WEP @ home
 #  + dhcpkiller
 #  + dokumentation
 #  
 # 04.10.25 19:34 v.0.0.2 -------
 #  + settings for the HTW 
 #  + runs under suse 9.1
 # 05.10.07 xx:xx v.0.0.3 -------
 #  + intersaar
 #  + hide scripts
 #  + kismet script
 # 05.10.10 13:10
 #  + manuel setup script angefangen
 #  
   
 # found ideas
 #        # Shut down all NFS mounts on this interface
 #        nfsstop ()
 #        {
 #            local HOST MT
 #            if read HOST MT ; then
 #                nfsstop
 #                if /sbin/ifuser $DEVICE $HOST ; then
 #                    do_fuser -k -m $MT > /dev/null
 #                    log umount -f -v $MT
 #                fi
 #            fi
 #        }
 #       mount -t nfs | sed -e 's/:.* on \(.*\) type .*/ \1/' | nfsstop
   
 WLANCTL="/sbin/wlanctl-ng"
 dhcpbin="/sbin/dhclient" 
 
 dhcpkill  ()
 {
  killproc -TERM $dhcpbin
 #ip route del default > /dev/null 2>&1
 }
 
 
 
 case "$1" in
 
 
 # exaple to copy
 #whome)
 #   dhcpkill;
 #    DEVICE="wlan0"
 #   echo "wlan daheim"
 # 
 #   #  iwconfig wlan0 key {key goes here} [1] # WEP encription 
 #   #
 #   ifconfig $DEVICE 192.168.12.22    # the IP
 #   ifconfig wlan0 10.0.0.88 netmask 255.255.255.255 broadcast 10.255.255.255
 #   #ip route del default > /dev/null 2>&1
 #   ip add default gw 192.168.12.1 # the Route
 #   # ip route flush cache
 #   # startproc $dhcpbin $DEVICE      # for DHCP
 #;;# ------------------------------------------------------

 
  lug)
   dhcpkill;
   echo " setting up the network for \"LUG\""
   #ifconfig eth0 down 
   #echo "Dissabling eth0"
   ifconfig eth0 192.168.199.88
   route add default gw 192.168.199.254
   # cp /etc/resolv.conf.lugsaar.blux /etc/resolv.conf
   exit 0;
 ;;# ------------------------------------------------------

 assy)
   dhcpkill;
     DEVICE="eth0"
   echo "DSL bei Astrid"
   #
   # ifconfig $DEVICE 192.168.12.22    # the IP
   ifconfig $DEVICE 192.168.0.22 netmask 255.255.255.0 broadcast 192.168.0.255
   route add default gw 192.168.0.1  # the Route
 ;;# ------------------------------------------------------

 
 
 whome)
   DEVICE="wlan0"
   dhcpkill;
   echo "wlan daheim OHNE WEP"
   $WLANCTL $DEVICE lnxreq_ifstate ifstate=enable
   $WLANCTL $DEVICE lnxreq_autojoin ssid=blux authtype=not_set
   ifconfig $DEVICE 192.168.12.22
   route add default gw 192.168.12.254
   #startproc $dhcpbin $DEVICE
   #/root/bin/wlan-online
   #route add default gw 192.168.201.254
 ;;# ------------------------------------------------------

 
 test)
   DEVICE="wlan0"
   dhcpkill;
   echo "test wlan fÃŒr unterwegs OHNE WEP"
   $WLANCTL $DEVICE lnxreq_ifstate ifstate=enable
   $WLANCTL $DEVICE lnxreq_autojoin ssid=Zlaja authtype=not_set
  echo "IP festlegen?? [J/N]"
  read BUF;
   if  [ $BUF = "J" ] || [ $BUF = "j" ] ; then
    ifconfig $DEVICE 192.168.0.22
    route add default gw 192.168.0.1
   else
    echo "starte DHCP auf $DEVICE"
    startproc $dhcpbin $DEVICE
   fi
 ;;# ------------------------------------------------------
   
   
   
 
 whomewep)
    dhcpkill;
     DEVICE="wlan0"
     KEY1="XX:XX:XX:XX:XX:XX:XX:XX:XX"
     echo "wlan mit WEP daheim"
 
    wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
    wlanctl-ng wlan0 lnxreq_hostwep decrypt=true encrypt=true  # for me this must be host-based encrypt.
    wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKeyID=1
    # which WEP key to use
    wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true
    wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11PrivacyInvoked=true
    wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey0="$KEY1"
    wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey1="$KEY1"
    #wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey2=<your:third:key:goes:here>
    #wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey3=<your:fourth:key:goes:here>
    wlanctl-ng wlan0 lnxreq_autojoin ssid="blux" authtype="opensystem"
    #wlanctl-ng wlan0 dot11DesiredBSSType="infrastructure"
 
 
 
 #   $WLANCTL $DEVICE lnxreq_ifstate  ifstate=enable
 #   $WLANCTL $DEVICE lnxreq_autojoin ssid="blux" authtype="sharedkey"
 #   $WLANCTL $DEVICE lnxreq_hostwep  decrypt=true encrypt=true
 #   $WLANCTL $DEVICE dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true
 #   $WLANCTL $DEVICE dot11req_mibset mibattribute=dot11PrivacyInvoked=true
 #   $WLANCTL $DEVICE dot11req_mibset mibattribute=dot11WEPDefaultKey0="$KEY1"
 #   $WLANCTL $DEVICE dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0
 #   $WLANCTL $DEVICE dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true
 #   $WLANCTL $DEVICE dot11req_mibset mibattribute=dot11PrivacyInvoked=true
   echo "Configured WEP encryption."
 
   #  iwconfig wlan0 key XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX [1]
   #
   ifconfig $DEVICE 192.168.0.2
   route add default gw 192.168.0.1
   # /sbin/dhclient wlan0
   # route add default gw 192.168.1.24
 ;;# ------------------------------------------------------

 manw)
 #
 # einlesen muss er SSID, IPsetzen oder dhcp[i/d](dhcp),route[j/n](route) 
 # weitereeinstellungen?[J/N](, MAC setzen[j/n](eingabe MAC),crypt[J/N](abfrage WPA))
 #
 #      Noch zu vollenden
 #
  readin()
  {
    echo "Freage $text [J/N]"
    read BUF;
   if  [ $BUF = "J" ] || [ $BUF = "j" ] ; then
    antwort="jawoll";
    else  antwort="nööö";
   fi;
 }  
    
   dhcpkill;
    DEVICE="wlan0"
   echo "Manuelle einstellungen auf $DEVICE ";
   tmp="";
    
   #  iwconfig wlan0 key {key goes here} [1] # WEP encription
   #
 #   ifconfig $DEVICE 192.168.12.22    # the IP
 #   ifconfig wlan0 10.0.0.88 netmask 255.255.255.255 broadcast 10.255.255.255
 #   #ip route del default > /dev/null 2>&1
 #   ip add default gw 192.168.12.1 # the Route
    # ip route flush cache
 #   # startproc $dhcpbin $DEVICE      # for DHCP
 ;;# ------------------------------------------------------

 
 home)
   dhcpkill;
   echo "Netzwerk HOME"
   echo "einstllungen home (rcnetwork restart)"
   /sbin/rcnetwork restart
   
   exit 0;
 ;;# ------------------------------------------------------
   
   
 ip)
   dhcpkill;
   DEVICE="eth0"
   
 #   echo "ipadresse"
 #  if [ -n "$2" ]  then
  
    echo "IP festlegen?? (192.168.0.2) oder DHCP [J/N]"
   read BUF;
   if  [ $BUF = "J" ] || [ $BUF = "j" ] ; then
    ifconfig $DEVICE 192.168.0.2
    route add default gw 192.168.0.1
  
   else
    echo "starte DHCP auf $DEVICE"
    startproc $dhcpbin $DEVICE
   fi
   
    
 #   echo "setze $DEVICE auf $2";
 #   ifconfig $DEVICE $2 
 #   
 #   exit 0;
 #  else 
 #   echo "Usage $0 ip [ IPadresse ]"
 #   exit 1; 
 #  fi;
 ;;# ------------------------------------------------------

 
 wlug)
   DEVICE="wlan0"
   dhcpkill;
   echo "wlan in der lug"
   $WLANCTL $DEVICE lnxreq_ifstate ifstate=enable
   $WLANCTL $DEVICE lnxreq_autojoin ssid=lug authtype=opensystem
 
   startproc $dhcpbin $DEVICE
   #/root/bin/wlan-online
   route add default gw 192.168.21.54
 ;;# ------------------------------------------------------

 kismet)
   dhcpkill;
   DEVICE="wlan0"
 
   echo "wlan fuer Kismet vorbereitet";
   $WLANCTL $DEVICE lnxreq_ifstate ifstate=enable
   #  $WLANCTL $DEVICE lnxreq_autojoin ssid=blackout authtype=not_set

   # startproc $dhcpbin $DEVICE
   # /root/bin/wlan-online
   # route add default gw 192.168.201.254
 ;;# ------------------------------------------------------

 
 wblack)
   dhcpkill;
   DEVICE="wlan0"
 
   echo "wlan im blackout, dhcp"
   $WLANCTL $DEVICE lnxreq_ifstate ifstate=enable
   $WLANCTL $DEVICE lnxreq_autojoin ssid=blackout authtype=not_set
 
   startproc $dhcpbin $DEVICE
   #/root/bin/wlan-online
   #route add default gw 192.168.21.24
 ;;# ------------------------------------------------------

 inter)
   dhcpkill;
   DEVICE="wlan0"
   MAC=00:14:BF:37:47:AE # eine aus dem Netz gefischte
   IP=10.254.97.4
   NETMASK=255.255.255.0
   #MAC=00:13:20:17:BE:23 # eine Erfundenen

   echo "wlan intersaar test";
   $WLANCTL $DEVICE lnxreq_ifstate ifstate=enable
   ifconfig $DEVICE down
   ifconfig $DEVICE hw ether $MAC
   ifconfig $DEVICE up
   echo " MAC auf $MAC gesetzt";
 
   $WLANCTL $DEVICE lnxreq_hostwep decrypt=false encrypt=false ;
 #   $WLANCTL $DEVICE dot11req_mibset mibattribute=dot11PrivacyInvoked=true ;
   $WLANCTL $DEVICE dot11DesiredBSSType="infrastructure"
   
   $WLANCTL $DEVICE lnxreq_autojoin ssid=intersaar-Hotspot authtype="opensystem" ;#authtype=not_set
   ifconfig $DEVICE $IP netmask $NETMASK
   echo "auf ip $IP gesetzt";
  #  startproc $dhcpbin $DEVICE
   #/root/bin/wlan-online
   #route add default gw 192.168.201.254
 ;;# ------------------------------------------------------
 
   
   
 
 
 mesh)
   dhcpkill;
   echo "wlan fÃŒr MobileMesh"
   $WLANCTL wlan0 lnxreq_ifstate ifstate=enable
   $WLANCTL wlan0 lnxreq_autojoin ssid=mesh authtype=opensystem
   
   # /sbin/wlanctl-ng wlan0 dot11req_start      \
   #            ssid=mesh                       \
   #            bsstype=independent             \
   #            beaconperiod=100                \
   #            dtimperiod=3                    \
   #            cfpollable=false                \
   #            cfpollreq=false                 \
   #            cfpperiod=3                     \
   #            cfpmaxduration=100              \
   #            probedelay=100                  \ 
   #            dschannel=6                     \
   #            basicrate1=2                    \
   #            basicrate2=4                    \
   #            operationalrate1=2              \
   #            operationalrate2=4              \
   #            operationalrate3=11             \   ifconfig wlan0 10.0.0.88 netmask 255.255.255.255 broadcast 10.255.255.255
   /usr/bin/mmdiscover -i wlan0
   /usr/bin/mmrp
   #/sbin/dhclient wlan0
   #/root/bin/wlan-online
   #route add default gw 192.168.201.254
 ;;# ------------------------------------------------------

 
 adhoc)
  dhcpkill;
   echo "wlan0 im ad-hoc modus"
  /sbin/wlanctl-ng wlan0 dot11req_start   \
               ssid=blux                  \
               authtype=opensystem        \
               ifstate=enable             \
               bsstype=independent       \
               beaconperiod=100           \
               dtimperiod=3               \
               cfpollable=false           \
               cfpollreq=false            \
               cfpperiod=3                \
               cfpmaxduration=100         \
               probedelay=100             \
               dschannel=8                \
               basicrate1=2               \
               basicrate2=4               \
               operationalrate1=2         \
               operationalrate2=4         \
               operationalrate3=11        \
               operationalrate4=22
 
        echo "!! Achtung !!   du musst die IP und so manuell setzen  !! Achtung !!"
 ;;# ------------------------------------------------------

 dhcp)
   DEVICE="eth0"
   dhcpkill;
   echo "dhcap auf eth0"
   startproc $dhcpbin $DEVICE
   #/root/bin/wlan-online
   #route add default gw 192.168.201.254
 ;;# ------------------------------------------------------

 fh)
   DEVICE="eth0"
   dhcpkill;
   echo "dhcp auf eth0 an der HTW mit VPN"
   startproc $dhcpbin $DEVICE
   sleep 3; 
   /usr/local/sbin/vpnc-connect
   #route add default gw 192.168.201.254
 ;;# ------------------------------------------------------
   
 wfh)
    dhcpkill;
     DEVICE="wlan0"
 #     KEY1="XX:XX:XX:X:XX:XXX:XX:XX:XX:XX:XC"
     KEY1=":XX::XX:XX:XX:XX::::"
     echo "wlan mit WEP an der HTW"
   
  
    wlanctl-ng $DEVICE lnxreq_ifstate ifstate=enable
    wlanctl-ng $DEVICE lnxreq_hostwep decrypt=true encrypt=true
    # for me this must be host-based encrypt.
    wlanctl-ng $DEVICE dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0
    # which WEP key to use
    wlanctl-ng $DEVICE dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true
    wlanctl-ng $DEVICE dot11req_mibset mibattribute=dot11PrivacyInvoked=true
    wlanctl-ng $DEVICE dot11req_mibset mibattribute=dot11WEPDefaultKey0="$KEY1"
 #    wlanctl-ng $DEVICE dot11req_mibset mibattribute=dot11WEPDefaultKey1="$KEY1"
    #wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey2=<your:third:key:goes:here>
    #wlanctl-ng wlan0 dot11req_mibset mibattribute=dot11WEPDefaultKey3=<your:fourth:key:goes:here>
    wlanctl-ng $DEVICE lnxreq_autojoin ssid="htw-wlan" authtype="opensystem"
    wlanctl-ng $DEVICE dot11DesiredBSSType="infrastructure"
    echo "Configured WEP encryption."
   # ifconfig $DEVICE 192.168.2.22
   #  route add default gw 192.18.12.1
  /sbin/dhclient wlan0
   # /root/bin/wlan-online
   # route add default gw 192.168.21.254
 ;;# ------------------------------------------------------
  ######################## Hidescripte ########################
  # um die MAC der Netzwerkkarten zu verstellen
   
 hidew)
   # MAC Hidescript fÃŒr Wlan
   DEVICE="wlan0"
   MAC="00:14:BF:31:CD:EE"
   echo "Setze die MAC von $DEVICE auf $MAC"
   ifconfig $DEVICE down
   ifconfig $DEVICE hw eth $MAC
   ifconfig $DEVICE up
 ;;# ------------------------------------------------------

 hidek)
   # MAC Hidescript fÃŒr Kabel
   DEVICE="eth0"
   MAC="00:14:BF:31:CD:EE"
   echo "Setze die MAC von $DEVICE auf $MAC"
   ifconfig $DEVICE down
   ifconfig $DEVICE hw eth $MAC
   ifconfig $DEVICE up
 ;;# ------------------------------------------------------

 
 
 
 *)
   echo "Usage: $0 { option [ IPadresse ]}";
   echo ;
   echo "Options :" ;
   echo " ---------------------------------------------------------";
   echo "| lug    : feste  IP  auf eth0  in der lug 192.168.1.88   |";
   echo "| wblack : dhcp       auf wlan0 im blackout               |";
   echo "| wlug   : dhcp       auf wlan0 fÃŒr wlan vor der lug      |";
   echo "| whome  : feste  IP  auf wlan0 daheim                    |";
   echo "| home   : feste  IP  auf eth0  fÃŒr daheim [192.168.1.2]|";
   echo "| ip     : eigene IP  auf eth0  setzen                    |";
   echo "| dhcp   : dhcp       auf eth0                            |";
   echo "| adhoc  : adhoc      auf wlan0 ; SSID=blux; cannel=8     |";
   echo "| fh     : dhcp       auf eth0  an der HTW mit VPN        |";
   echo "| wfh    : dhcp       auf wlan0 an der FH WLAN            |";
   echo "|--   ---      besondere netze oder scripte       ---   --|";
   echo "| kismet :  -     -   auf wlan0 ;fÃŒr kismet vorbereitet   |";
   echo "| inter  :   test auf intersaar mit fester ip und hide    |";
   echo "| test   :   test fÃŒr unterwegs ohne hide                 |";
   echo "| manw   : manuelles setupscript auf wlan0, inc MAC       |";
   echo "| --------------------------------------------------------|";
   echo "| hidescripte setzen andere MAC auf die devices:          |";
   echo "| hidew  :            auf wlan0 (wlan)                    |";
   echo "| hidek  :            auf eth0  (kabel)                   |";
   echo " ---------------------------------------------------------";
   echo "by Bernd Lux. 04.10.07";
   ;; # ------------------------------------------------------
 esac;
 
 exit 0;

Bernd 2005/12/07 12:26

 
linux_scripts/linux_network.sh.txt · Zuletzt geändert: 2006/04/01 14:37
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki