[Wylug-help] Running script on connection to certain wireless network.

Timothy Baldwin timbaldwin at fastmail.co.uk
Fri May 22 15:10:07 UTC 2009


On Mon, 18 May 2009 14:52 +0100, "Martyn Ranyard"
<ranyardm at gmail.com> wrote:

>  The best way I can think is to run a script on connection and
>  disconnection and in it use something like the following :
>
>  if iwconfig | grep 'ESSID:"MyNetworkName"; then
>    # Do something clever
>  fi

Great idea, in the end I used the MAC of the access point.

In /etc/NetworkManager/dispatcher.d/02_6to4 I put:

#!/bin/sh
exec >> /dev/null 2>&1

if test "x$1" != "xra0"; then
  exit 0
fi

if test "x$2" == "xup" && iwconfig ra0 | grep '00:04:E2:A6:93:80'; then
  sysctl -w net.ipv6.conf.default.forwarding=1
  net.ipv6.conf.all.forwarding=1
  ip -6 address add dev ra0 local 2002:c000:0202:1234::8/64
  ifup tun6to4
  logger 6t04 started
else
  ip -6 address del dev ra0 local 2002:c000:0202:1234::8/64
  ifdown tun6to4
  sysctl -w net.ipv6.conf.default.forwarding=0
  net.ipv6.conf.all.forwarding=0
  logger 6to4 stopped
fi


Which works with the following in /etc/network/interfaces:

iface tun6to4 inet6 v4tunnel
        address 2002:c000:0202:1234::8
        netmask 16
        endpoint any local 10.211.92.206
        up ip -6 route add ::/96 dev tun6to4 metric 1
        up ip -6 route add 2000::/3 via ::192.88.99.1 dev tun6to4 metric
        1
        down ip -6 route flush dev tun6to4
        up ip -4 address add dev ra0 local 10.211.92.206/24
        down ip -4 address del dev ra0 local 10.211.92.206/24 || true
        up start-stop-daemon -o -n arping -p /var/run/arping_router -b
        -m --start --startas /usr/sbin/arping -- -i ra0 -t
        00:d0:41:a0:ed:07 -w 60000000 router
        up start-stop-daemon -o -n arping -p /var/run/arping_anycast -b
        -m --start --startas /usr/sbin/arping -- -i ra0 -t
        00:d0:41:a0:ed:07 -S 10.211.92.206 10.211.92.206
        down start-stop-daemon -o -n arping -p /var/run/arping_router -m
        --stop
        down start-stop-daemon -o -n arping -p /var/run/arping_anycast
        -m --stop
        mtu 1472
        ttl 255

The laptop becomes a 6to4 router, using a anycast forwarding rule in my
IPv4 ADSL NAT router.



More information about the Wylug-help mailing list