#!/bin/ksh # /home/root/bin/gethost # no Copyright James Mar 17, 1998. # Nothing i'm really proud of (except maybe the idea ...) timeout=15 # SNMP timeout in milliseconds retries=3 # number of retries for snmpget commstring=$2 if [ "$commstring" = "" ] ; then commstring=public ; fi if [ "`snmpget -c $commstring -r$retries -t$timeout "$1" system.sysUptime.0 2>/dev/null`" = "" ] ; then echo "# host:$1 community string:$commstring - unreachable? SNMP? community? - exit..." exit 0 fi sysName0=`snmpget -c $commstring -d -t15 -r3 "$1" system.sysName.0 2>/dev/null | \ grep "OCTET STRING (0x4)" | awk -F\" '{print $2}' | sed 's/ //g'` sysContact0=`snmpget -c $commstring -d -t15 -r3 "$1" system.sysContact.0 2>/dev/null | \ grep "OCTET STRING (0x4)" | awk -F\" '{print $2}' | sed 's/ //g'` sysLocation0=`snmpget -c $commstring -d -t15 -r3 "$1" system.sysLocation.0 2>/dev/null | \ grep "OCTET STRING (0x4)" | awk -F\" '{print $2}' | sed 's/ //g'` if [ "$sysName0" = "" ] ; then sysName0="sysName.0" ; fi if [ "$sysContact0" = "" ] ; then sysContact0="sysContact.0" ; fi if [ "$sysLocation0" = "" ] ; then sysLocation0="sysLocation.0" ; fi dotcol2=`echo $1|cut -c2,2` dotcol3=`echo $1|cut -c3,3` dotcol4=`echo $1|cut -c4,4` if [ "$dotcol2" != "." -a "$dotcol3" != "." -a "$dotcol3" != "." -a \ "$sysName0" != "$1" ] ; then echo "# $1 $sysName0 #$sysContact0 #$sysLocation0 # different hostname at commandline" fi # so ein SCHAAAAAAAS umask ugo+w pimpel=/tmp/qwe.rnetstat.$RANDOM rnetstat -I $1|grep -vE "127.0.0.1|Network Mask"| \ sed 's/ / #/1'| \ awk '{print $2, $1, $5}'|grep -v "^ "| \ sed 's/Fddi/1.Fddi/g'|sed 's/ATM/6.ATM/g'| \ sed 's/Token/3.Token/g'| \ sed 's/Ether/4.Ether/g'| \ sed 's/Serial/7.Serial/g'| \ sed 's/Tunnel/9.Tunnel/g'|sed 's/Loop/9.Loop/g'| \ sort -k2|nocr >$pimpel awk '{print $1"\t"sysN" "sysC" "sysL" #"$2, $3}' sysN=$sysName0 sysC=`echo "#$sysContact0"` sysL=`echo "#$sysLocation0"` $pimpel rm $pimpel 2>/dev/null exit 0 ichint=`snmpget -t $timeout -r $retries $1 interfaces.ifNumber.0 | cut -d : -f 3|awk '{print $1}'` if [ "$ichint" = "" ] ; then exit 0 ; fi intloop=1 while [ $intloop -le $ichint ] do for ichipa in `snmpwalk -t $timeout -r $retries $1 ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex 2>/dev/null | grep "INTEGER: $intloop"|awk '{print $1}'|awk -F "." '{print $5"."$6"."$7"."$8}'` do if [ "$ichipa" != "" -a "`echo $ichipa|awk '{print $2}'`" = "" -a "$ichipa" != "127.0.0.1" ] ; then ichnam=`snmpget -t $timeout -r $retries $1 interfaces.ifTable.ifEntry.ifDescr.$intloop 2>/dev/null | cut -d : -f 3|awk '{print $1}'` ichtyp=`snmpget -t $timeout -r $retries $1 interfaces.ifTable.ifEntry.ifType.$intloop 2>/dev/null | cut -d : -f 3|awk '{print $1}'` ichphy=`snmpget -t $timeout -r $retries $1 interfaces.ifTable.ifEntry.ifPhysAddress.$intloop 2>/dev/null | awk 'BEGIN { FS = "\n"; RS = "" } { print $NF }'|awk '{ print $2 $3 $4 $5 $6 $7 }'|grep [0-9]` if [ "$ichphy" = "" ] ; then ichphy="unknown" ; fi ichtyp=`echo $ichtyp|sed 's/ppp/#ppp/g'|sed 's/prop/#prop/g'|sed 's/rfc877/#rfc877/g'|sed 's/frame/#frame/g'|sed 's/other/#other/g'` echo $ichipa"\t"$sysName0 " #"$sysContact0 "#"$sysLocation0 "#"$ichtyp 0x$ichphy $ichnam fi done intloop=`expr $intloop + 1` done