Tuesday, June 8, 2010

Automatic static ARP-Table

Today I have tried to automate the static arp entries. Fortunately my Linux-Laptop has a wonderful Networkmanager. His dispatcher daemon supports shellscripts which will be executed during the different states of connecting to a network.


With this script my arp-entries will be automatically set when I connect to the wireless network of my university.
Less chances for scriptkiddies.


#!/bin/sh

## read params
INTERFACE=$1
ACTION=$2

## ESSID

ESSID_UNI=""
## IP
IP_UNI=""
## MAC 

MAC_UNI=""

## get ESSID of connected Network

ESSID=$(nm-tool | grep \* | cut -d"*" -f2 -s | cut -d":" -f1 -s)



## get displaynum for notify

if [ -z "$DISPLAY" ]; then
    console=`fgconsole`
    dispnum=`ps t tty$console | sed -n -re 's,.*/X(org)? .*:([0-9]+).*,\2,p'`
    export DISPLAY=":$dispnum"
fi


## set XAUTHORITY for notify
if [ -z "$XAUTHORITY" ]; then
    export XAUTHORITY=/home/bluecore/.Xauthority
fi
           
case "$ACTION" in
    up)
        if [ "$ESSID" = "$ESSID_UNI" ]; then
            /sbin/arp -s $IP_UNI $MAC_UNI
            notify-send -i network-wired "ARP-Table
`/sbin/arp -an | grep $IP_UNI`"

        fi
        ;;
esac
Greetz
BlueC0re

No comments:

Post a Comment