Login
Newsletter
Werbung

So, 29. Dezember 2002, 00:00

Online-Indikator

Vorwort

In diesem Artikel geht es darum, die Keyboard-LEDs nach Netzwerkverkehr blinken zu lassen, an- und auszuschalten, je nach Online-Status.

Er ist eine Anleitung, die Keyboard-LEDs zu manipulieren, je nach Netzwerkverkehr und Online-Status in Abhängigkeit von Paketfluß auf einem Netzwerkinterface und Router Internet Protokoll-Auswertung.

Wer seinen Monitor ausschaltet oder erst gar keinen benutzt, ist sicherlich daran interessiert, Status-LEDs über Netzwerkaktivitäten zu erhalten.

Wer einen Router im Einsatz hat, kann die ungenutzten LEDs der Tastatur aktivieren, um den Online-Status anzeigen zu lassen. Natürlich funktioniert das auch auf jedem anderen Computer.

Netzwerkverkehr auf einem Netzwerkinterface anzeigen

Um den Netzwerkverkehr auf den Keyboard-LEDs anzuzeigen, kann man tleds verwenden. Es werden NUM und SCROLL verwendet, um ein- und ausgehenden Netzwerkverkehr anzuzeigen, d. i. fest "verdrahtet".

Anwender von X11 sollten sich für xsetleds interessieren und ggf. im Skript ersetzen. Sorry für den indirekten Link, aber bei Erstellung des Dokuments war das Root-Directory nicht erreichbar.

Online-Status mit einem Netgear-Router aufzeigen

Um den Online-Status mit einem Netgear-Router aufzuzeigen, kann man mein Skript verwenden. Es ist kommentiert und sollte offene Fragen beantworten können. Selbstverständlich kann das Skript mit anderen Routern, die Routing Internet Protokolle (RIP) senden, verwendet werden. Die selektierte LED (default CAP) ist an, wenn der Router online ist, sonst aus.

Der Vorteil meines Skripts ist, daß kein Netzwerkverkehr erzeugt wird, die Analyse erfolgt über Auswertung des bestehenden Netzwerkverkehrs. Damit ist das Skript Auswertungstools von RIP und SNMP überlegen und wird z.B. nicht von anderen Rechnern entdeckt. Die CPU-Belastung ist gering bis moderat.

Mit den verwendeten Defaults für die LED-Ausgabe können beide Tools parallel verwendet werden.

Und hier ist das Skript:

#!/bin/sh
# PRECAUTIONS:
# You have to install
# -tcpdump
# -setleds
#
# If you haven't already to use this script!
# Read `man setleds` if your led does not work.
# It might not work, too, if you use another software
# to control the other leds (depends).
#
# LICENSE: artistic GPL, not included, because it
# is freely downloadable.
#
# AUTHOR : Sascha Wuestemann
# MAIL : sascha@killerhippy.de
# date : 20021210
# VERSION: 1.0
#
###################################################
# DESCRIPTION: #
# script for bootup or $HOME/.bash_login scripts, #
# to automagically highlight selected led over #
# all 8 ttys if we are online with our netgear- #
# router, else downlight them. #
###################################################
#
# Additionally, the online status is dumped to
# INFOFILE which contains "online with <internal-ip>"
# or "offline". Unfortunately, <internal-ip> _is_not_
# the ip you are using to walk the internet, but the
# ip the router uses at the inside. Nevertheless it
# indicates the online status.
#
# This script acts like a a deamon (is listed at ps).
# If you are worried about writing to your harddisk
# every 30 seconds, forget about that, Linux is
# aware about such and buffers it. If you don't
# believe in this, move the tempfiles to ramdisk
# yourself!
#
# TEMPFILE is needed to pass information and
# automatically deleted, while the script runs.
# If powerdown or else, del /tmp/onlinefile*
# /tmp/OnlineStatus
#
# You have to enable RIP with the direction "Both"
# or "Out Only" and the version RIP-1, RIP-2B or RIP-2M
# (only tested with these) to match against the script's
# logic. If your netgear-router only uses newer router
# information protocolls, send me a tcpdump.
#
# RIP-? sends router information every 30 seconds.
#
# A sample tcpdump:
#
# 18:46:06.374316 <netgear-ip>.520 > <three bytes net>.255.520:\
# RIPv1-resp &#91;items 2&#93;: {0.0.0.0}(1) {<actual internal ip>}(1) &#91;ttl 1&#93;
# user config starts here:
LED="caps" 			# can be "caps", "scroll", "num"
IFACE="eth1"			# networkinterface to watch
TEMPFILE="/tmp/onlinefile$$"
INFOFILE="/tmp/OnlineStatus"
NETWATCH="/usr/sbin/tcpdump"
SLEEPER="/bin/sleep 30s"	# how long to wait for RIP information
NETWATCH_OPTION_1="-q -c 1 -p -s0 -i $IFACE -n port 520 -w $TEMPFILE"
NETWATCH_OPTION_2="-r $TEMPFILE"
MATCH="port 520"
# user config has ended
#
# only script programmers should change things below
# subfunctions
leds ()
{
	&#91; "$1" = "online" &#93; && SCROLL_OPTION="+$LED" \
	|| SCROLL_OPTION="-$LED"
 local INITTY=/dev/tty&#91;1-8&#93;
 for TTY in $INITTY; do
 /usr/bin/setleds -L $SCROLL_OPTION <$TTY
 done
 echo "$1 with $ONLINE" > $INFOFILE
}
ledsreset ()
{
	INITTY=/dev/tty&#91;1-8&#93;
	for tty in $INITTY; do
 	 setleds -L < $tty
 	done
}
# catch aborts and clean
trap 'rm -f $TEMPFILE; rm -f $INFOFILE; \
ledsreset 1>/dev/null 2>&1; exit 32' 0
# simulate daemon
while true; do
 # send tcpdump into background and
	# save its pid
 $NETWATCH $NETWATCH_OPTION_1 &
	MYPID=$!
 # wait selected seconds (default 30)
 $SLEEPER
 # in case of, kill tcpdump with grace
	kill $MYPID >/dev/null 2>&1
 # read what we have recieved from tcpdump
 HIT=`$NETWATCH $NETWATCH_OPTION_2`
 # extract the second ip named "actual internal ip" above
 ONLINE=`echo $HIT | sed -n -e "s/^.*{//p"| sed -n -e "s/}.*$//p"`
 # test, if we recieved information at all
	if &#91; $ONLINE &#93;; then
 # ip is 0.0.0.0 if the router is offline
 if &#91; $ONLINE == 0\.0\.0\.0 &#93;; then
 leds offline
 else
 leds online
 fi
	else
	 leds offline
	fi
	# erase garbage tempfile
 rm $TEMPFILE
done

Für die Implementierung kann ich leider keine Unterstützung liefern, z.B. ist mir unbekannt (und das wird voraussichtlich hoffentlich so bleiben), wie SuSE seine Startskripte handhabt. Bitte versucht erst durch die Suche auf dieser Seite mit der SUCHE-Funktion euer Problem zu lösen, wenn das nicht hilft, stellt eine Anfrage im Forum.

Vielen Dank und viel Spass!

Kommentare (Insgesamt: 0 )
Pro-Linux
Pro-Linux @Facebook
Neue Nachrichten
Werbung