# This module contains the common routines for the snmpInfo List and Table
# programs. The routines here are mostly concerned with getting the data from
# various system commands, and putting it into various globals.
#
require "oidorder.pm";
$HH = '[0-9a-fA-F][0-9a-fA-F]';
if ($D>1) {
print "
argc is $#ARGV, argv is \"@ARGV\"\n";
print "
\$0 is \"$0\"\n";
print "
\n";
}
if ($D > -1) {
$ENV{'AUTH_TYPE'} = '' if !$ENV{'AUTH_TYPE'};
$ENV{'CONTENT_LENGTH'} = '' if !$ENV{'CONTENT_LENGTH'};
$ENV{'CONTENT_TYPE'} = '' if !$ENV{'CONTENT_TYPE'};
$ENV{'GATEWAY_INTERFACE'} = '' if !$ENV{'GATEWAY_INTERFACE'};
$ENV{'HTTP_ACCEPT'} = '' if !$ENV{'HTTP_ACCEPT'};
$ENV{'PATH_INFO'} = '' if !$ENV{'PATH_INFO'};
$ENV{'PATH_TRANSLATED'} = '' if !$ENV{'PATH_TRANSLATED'};
$ENV{'QUERY_STRING'} = '' if !$ENV{'QUERY_STRING'};
$ENV{'REMOTE_ADDR'} = '' if !$ENV{'REMOTE_ADDR'};
$ENV{'REMOTE_HOST'} = '' if !$ENV{'REMOTE_HOST'};
$ENV{'REMOTE_USER'} = '' if !$ENV{'REMOTE_USER'};
$ENV{'REQUEST_METHOD'} = '' if !$ENV{'REQUEST_METHOD'};
$ENV{'SCRIPT_NAME'} = '' if !$ENV{'SCRIPT_NAME'};
$ENV{'SERVER_NAME'} = '' if !$ENV{'SERVER_NAME'};
$ENV{'SERVER_PORT'} = '' if !$ENV{'SERVER_PORT'};
$ENV{'SERVER_PROTOCOL'} = '' if !$ENV{'SERVER_PROTOCOL'};
$ENV{'SERVER_SOFTWARE'} = '' if !$ENV{'SERVER_SOFTWARE'};
}
if ($D>1) {
print "Environment:\n";
for $v (sort keys %ENV) {
print "- $v=\"$ENV{$v}\"\n";
}
print "
\n";
}
%get = ( # Group name => function name.
'df', 'dftbl',
'if', 'iftbl',
'ip', 'iptbl',
'usr', 'usrtbl',
);
# We recognize these MIB symbols (groups and variables). The value is
# a 1-char type indicator: 'v' for variables, 'g' for groups, and 't'
# for tables.
%mib = (
'all', 'g',
'snmp', 'g',
'system', 'g',
'sys', 'g',
'sysDescr', 'v',
'sysObjectID', 'v',
'sysUpTime', 'v',
'sysContact', 'v',
'sysName', 'v',
'sysLocation', 'v',
'sysServices', 'v',
'interfaces', 'g',
'if', 'g',
'ifNumber', 'v',
'ifTable','t',
'ifEntry', 'e',
'ifIndex', 'vv',
'ifDescr', 'vv',
'ifType', 'vv',
'ifMtu', 'vv',
'ifSpeed', 'vv',
'ifPhysAddress', 'vv',
'ifAdminStat', 'vv',
'ifOperStat', 'vv',
'ifLastChange', 'vv',
'ifInOctets', 'vv',
'ifInUcastPkts', 'vv',
'ifInNUcastPkts', 'vv',
'ifInDiscards', 'vv',
'ifInErrors', 'vv',
'ifInUnknownProtos', 'vv',
'ifOutOctets', 'vv',
'ifOutUcastPkts', 'vv',
'ifOutNUcastPkts', 'vv',
'ifOutDiscards', 'vv',
'ifOutErrors', 'vv',
'ifOutQLen', 'vv',
'at', 'g',
'atTable','t',
'atEntry', 'e',
'atIfIndex', 'v',
'atPhysAddress', 'v',
'atNetAddress', 'v',
'ip', 'g',
'ipForwarding', 'sv',
'ipDefaultTTL', 'sv',
'ipInReceives', 'sv',
'ipInHdrErrors', 'sv',
'ipInAddrErrors', 'sv',
'ipForwDatagrams', 'sv',
'ipInUnknownProtos', 'sv',
'ipInDiscards', 'sv',
'ipInDelivers', 'sv',
'ipOutRequests', 'sv',
'ipOutDiscards', 'sv',
'ipOutNoRoutes', 'sv',
'ipReasmTimeout', 'sv',
'ipReasmRecords', 'sv',
'ipReasmOKs', 'sv',
'ipReasmFails', 'sv',
'ipFragOKs', 'sv',
'ipFragFails', 'sv',
'ipFragCreates', 'sv',
'ipAddrTable','t',
'ipAddrEntry', 'e',
'ipAdEntAddr', 'v',
'ipAdEntIfIndex', 'v',
'ipAdEntNetMask', 'v',
'ipAdEntBcastAddr', 'v',
'ipRoutes', 'sv',
'ipRoutingTable','t',
'ipRouteEntry', 'e',
'ipRouteDest', 'v',
'ipRouteIfIndex', 'v',
'ipRouteMetric1', 'v',
'ipRouteMetric2', 'v',
'ipRouteMetric3', 'v',
'ipRouteMetric4', 'v',
'ipRouteNextHop', 'v',
'ipRouteType', 'v',
'ipRouteProto', 'v',
'ipRouteAge', 'v',
'icmp', 'g',
'icmpInMsgs', 'v',
'icmpInErrors', 'v',
'icmpInDestUnreachs', 'v',
'icmpInTimeExcds', 'v',
'icmpInParmProbs', 'v',
'icmpInSrcQuenchs', 'v',
'icmpInRedirects', 'v',
'icmpInEchos', 'v',
'icmpInEchoReps', 'v',
'icmpInTimestamps', 'v',
'icmpInTimestampReps', 'v',
'icmpInAddrMasks', 'v',
'icmpInAddrMaskReps', 'v',
'icmpOutMsgs', 'v',
'icmpOutErrors', 'v',
'icmpOutDestUnreachs', 'v',
'icmpOutTimeExcds', 'v',
'icmpOutParmProbs', 'v',
'icmpOutSrcQuenchs', 'v',
'icmpOutRedirects', 'v',
'icmpOutEchos', 'v',
'icmpOutEchoReps', 'v',
'icmpOutTimestamps', 'v',
'icmpOutTimestampReps', 'v',
'icmpOutAddrMasks', 'v',
'icmpOutAddrMaskReps', 'v',
'tcp', 'g',
'tcpRtoAlgorithm', 'v',
'tcpRtoMin', 'v',
'tcpRtoMax', 'v',
'tcpMaxConn', 'v',
'tcpActiveOpens', 'v',
'tcpPassiveOpens', 'v',
'tcpAttemptFails', 'v',
'tcpEstabResets', 'v',
'tcpCurrEstab', 'v',
'tcpInSegs', 'v',
'tcpOutSegs', 'v',
'tcpRetransSegs', 'v',
'tcpConnTable','t',
'tcpConnEntry', 'e',
'tcpConnState', 'v',
'tcpConnLocalAddress', 'v',
'tcpConnLocalPort', 'v',
'tcpConnRemAddress', 'v',
'tcpConnRemPort', 'v',
'udp', 'g',
'udpInDatagrams', 'v',
'udpNoPorts', 'v',
'udpInErrors', 'v',
'udpOutDatagrams', 'v',
'egp', 'g',
'egpInMsgs', 'v',
'egpInErrors', 'v',
'egpOutMsgs', 'v',
'egpOutErrors', 'v',
'egpNeighTable','t',
'egpNeighEntry', 'e',
'egpNeighState', 'v',
'egpNeighAddr', 'v',
# Disk group added by jc:
'df', 'g',
'dfNumber', 'v',
'dfTable','t',
'dfEntry', 'e',
'dfIndex', 'vv',
'dfPartition', 'vv',
'dfTotalKB', 'vv',
'dfUsedKB', 'vv',
'dfFreeKB', 'vv',
'dfFreePct', 'vv',
'dfDirectory', 'vv',
# User group added by jc:
'usr', 'g',
'usrNumber', 'sv',
'usrTable','t',
'usrEntry', 'e',
'usrIndex', 'vv',
'usrName', 'vv',
'usrUid', 'vv',
'usrGid', 'vv',
'usrDescr', 'vv',
'usrHome', 'vv',
'usrShell', 'vv',
'usrPlan', 'vv',
);
$ipadp = '\d+\.\d+\.\d+\.\d+';
$ntadp = '[.\d]+';
$ipptp = "$ipadp:\\d+";
$ethadp = "$HH:$HH:$HH:$HH:$HH:$HH";
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Here's a routine to run arp to get the ARP table, and examine its output
# for anything interesting.
sub attbl {
local($ifnt,$i);
local(@attb) = `arp -a`;
local($Addr,$HWtp,$HWaddr,$Flags,$Mask);
print "
#attbl ...\n" if $D>1;
for $ifnt (@attb) {
if (($Addr,$HWtp,$HWaddr,$Flags,$Mask)
=~ "^($ipadp)\s+(.*)\s+($ethadp)\s+(\s+)\s+(.*)") {
}
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
$dfpat1 = "(\\S+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)%*\\s+(\\S+)\\s+";
#
sub dftbl {
local($dfnt,$i);
local(@dftb) = `df`;
local($Partition,$TotalKB,$UsedKB,$FreeKB,$FreePct,$Directory);
# Partition TotalKB UsedKB FreeKB FreePct Directory
print "
#dftbl ...\n" if $D>1;
for $dfnt (@dftb) {
if ($dfnt =~ /^Filesystem/) {
print "
#dftbl Ignore $dfnt" if $D>2;
} elsif ($dfnt =~ /^node\s+Mtu/) { # Ultrix netstat.
print "
#dftbl Ignore $dfnt" if $D>2;
} elsif (($Partition,$TotalKB,$UsedKB,$FreeKB,$FreePct,$Directory)
= ($dfnt =~ $dfpat1)) { # BSD-style df output.
++$i;
print "
#dftbl i=$i matched dfpat1.\n" if $D>2;
$dfIndex[$i] = $i;
$dfPartition[$i] = $Partition;
$dfTotalKB[$i] = $TotalKB;
$dfUsedKB[$i] = $UsedKB;
$dfFreeKB[$i] = $FreeKB;
$dfFreePct[$i] = $FreePct;
$dfDirectory[$i] = $Directory;
}
print "
#dftbl Done with $dfnt\n" if $D>2;
}
$cnt{'df'} = $dfNumber = $i;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# This sets the global $fmt variable to indicate whether we're producing HTML
# lists or tables.
sub format {
local($f) = @_;
if ($f =~ /Table/i) { # Produce HTML tables.
$fmt = 'T';
} else {
$fmt = 'L'; # Default to list.
}
print "
# format `$fmt'\n" if $D>1;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Figure out this system's primary name, and leave it in $sysName.
sub getname {
if ($sysName = `hostname`) {
print "
#sysName hostname gave $sysName" if $D>2;
} elsif ($sysName = `uname -n`) {
print "
#sysName uname -n gave $sysName" if $D>2;
} else {
$sysName = 'localhost';
}
$sysName =~ s/\s+$//;
$sysName;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# This routine HTMLizes strings for transmission to a client. We should try
# to find a general-purpose, "correct" routine for this.
sub html {
local($x) = @_;
(local($y) = $x) =~ s/\s+$//;
$y =~ s/\</g;
$y =~ s/>/\>/g;
$y;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# &ifconfig(i,name)
# Call the ifconfig command for a particular interface, and extract all the
# recognizable data from its output. We are passed the ifIndex number and the
# interface's symbolic name.
# Iface MTU Network Address Ipkts Ierrs Opkts Oerrs
$ifpat1 = "^(\\w+)\\s+(\\d+)\\s+(\\d+)\\s+($ipadp)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)";
# Iface MTU Network Address Ipkts Ierrs Opkts Oerrs
$ifpat2 = "^(\\w+)\\s+(\\d+)\\s+($ntadp)\\s+($ipadp)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+";
# Iface MTU Met RX_OK RX_ERR RX_DRP RX_OVR TX_OK TX_ERR TX_DRP TX_OVR Flags
$ifpat3 = '^(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\w+)$';
# Iface MTU Network/NM Address Ipkts Ierrs Opkts Oerrs
$ifpat4 = '^(\w+)\s+(\d+)\s+([\d./]+)\s+([\d.]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)';
#
sub ifconfig {
local($i,$iface) = @_;
local(@ifcfg) = `ifconfig $iface`;
local($e, $ipad);
print "
#ifconfig($i,$iface) ...\n" if $D>2;
for $line (@ifcfg) {
if ($line =~ /^$iface:\s*($ipadp)\s/) {
$ipad = $1;
$ipAdEntAddr{$ipad} = $ipad;
$atNetAddress{$ipad} = $ipad;
$ipAdEntIfIndex{$ipad} = $i;
$atIfIndex{$ipad} = $i;
$ifNetAddr{$iface} = $ipad;
}
if ($line =~ /\binet addr:\s*($ipadp)\b/i) {
$ipad = $1;
$ipAdEntAddr{$ipad} = $ipad;
$atNetAddress{$ipad} = $ipad;
$ipAdEntIfIndex{$ipad} = $i;
$atIfIndex{$ipad} = $i;
$ifNetAddr{$iface} = $ipad;
$atPhysAddress{$ipad} = $e if $ipad && $e;
}
if ($line =~ /\bUP\b/i) {
$ifOperStat[$i] = 1;
print "
#ifconfig Up.\n" if $D>2;
} elsif ($line =~ /\bDOWN\b/i) {
$ifOperStat[$i] = 2;
print "
#ifconfig Down.\n" if $D>2;
}
$ifAdminStat[$i] = 0;
if ($line =~ /\bEthernet\b/i) {
$ifType[$i] = 6;
print "
#ifconfig Ethernet.\n" if $D>2;
} elsif ($line =~ /\bLoopback\b/i) {
$ifType[$i] = 1;
print "
#ifconfig Loopback.\n" if $D>2;
}
if ($line =~ /\bHWaddr\s+($ethadp)\b/) {
$e = $1;
$ifPhysAddress[$i] = $e;
}
if ($line =~ /\bMask:\s*($ipadp)\b/i) {
$ipAdEntNetMask{$ipad} = $1;
}
if (($line =~ /\bBcast:\s*($ipadp)\b/i) || ($line =~ /\bbroadcast:\s*($ipadp)\b/i)) {
($x = $1) =~ s/.*\.//;
if ($x =~ /\.0$/) {
$ipAdEntBcastAddr{$ipad} = 0;
} else {
$ipAdEntBcastAddr{$ipad} = 1;
}
}
if ($line =~ /\bLink encap:(\d+)Mbps\b/i) {
$ifSpeed[$i] = $1 * 1000000;
}
if (($h1,$h2,$h3,$h4) = ($line =~ /netmask\s+($HH)($HH)($HH)($HH)+/)) {
$i1 = hex($h1);
$i2 = hex($h2);
$i3 = hex($h3);
$i4 = hex($h4);
$ipAdEntNetMask{$ipad} = "$i1.$i2.$i3.$i4" if $ipad;
}
}
if (!$ifPhysAddress[$i]) {
if ($e = `addr -e $iface`) {
$e =~ s/\s+$//;
$ifPhysAddress[$i] = $e;
$ifType[$i] = 6; # It has an Ethernet address.
}
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub ipadtbl {
print "
# ipadtbl ...\n";
&iftbl() if !defined $ifNumber;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub iftbl {
local($ifnt,$i);
local(@iftb) = `netstat -in`;
local($Iface,$MTU,$Net,$NM,$Addr,$Ipkts,$Ierrs,$Opkts,$Oerrs);
local($RX_OK,$RX_ERR,$RX_DRP,$RX_OVR,$TX_OK,$TX_ERR,$TX_DRP,$TX_OVR,$Flags);
print "
#iftbl ...\n" if $D>1;
for $ifnt (@iftb) {
if ($ifnt =~ /^Kernel/) {
print "
#iftbl Ignore $ifnt" if $D>2;
} elsif ($ifnt =~ /^Iface\s+MTU/) { # Linux netstat.
print "
#iftbl Ignore $ifnt" if $D>2;
} elsif ($ifnt =~ /^Name\s+Mtu/) { # Ultrix netstat.
print "
#iftbl Ignore $ifnt" if $D>2;
} elsif (($Iface,$MTU,$Net,$Addr,$Ipkts,$Ierrs,$Opkts,$Oerrs)
= ($ifnt =~ $ifpat1)) { # BSD-style netstat data line with two host addresses.
++$i;
print "
#iftbl i=$i matched ifpat1.\n" if $D>2;
$ifIndex[$i] = $ifIndex{$Iface} = $i;
$ipAdEntIfIndex{$Addr} = $atIfIndex{$Addr} = $i if $Addr;
$ifDescr[$i] = $Iface;
$ifMtu[$i] = $MTU;
$ipInReceives += ($ifInPkts[$i] = $Ipkts);
$ipOutRequests += ($ifOutPkts[$i] = $Opkts);
$ifInErrors[$i] = $Ierrs;
$ifOutErrors[$i] = $Oerrs;
&ifconfig($i,$ifDescr[$i]) if ($ifDescr[$i]);
print "
#iftbl ifconfig for $Iface done.\n" if $D>2;
} elsif (($Iface,$MTU,$Net,$Addr,$Ipkts,$Ierrs,$Opkts,$Oerrs)
= ($ifnt =~ $ifpat2)) { # BSD-style netstat data line with network and host addr.
++$i;
print "
#iftbl i=$i matched ifpat2.\n" if $D>2;
$ifIndex[$i] = $ifIndex{$Iface} = $i;
$ipAdEntIfIndex{$Addr} = $atIfIndex{$Addr} = $i if $Addr;
$ifDescr[$i] = $Iface;
$ifMtu[$i] = $MTU;
$ipInReceives += ($ifInPkts[$i] = $Ipkts);
$ipOutRequests += ($ifOutPkts[$i] = $Opkts);
$ifInErrors[$i] = $Ierrs;
$ifOutErrors[$i] = $Oerrs;
&ifconfig($i,$ifDescr[$i]) if ($ifDescr[$i]);
print "
#iftbl ifconfig for $Iface done.\n" if $D>2;
} elsif (($Iface,$MTU,$Net,$RX_OK,$RX_ERR,$RX_DRP,$RX_OVR,$TX_OK,$TX_ERR,$TX_DRP,$TX_OVR,$Flags)
= ($ifnt =~ $ifpat3)) { # Linux netstat data line..
++$i;
print "
#iftbl i=$i matched ifpat3.\n" if $D>2;
$ifIndex[$i] = $ifIndex{$Iface} = $i;
&ifconfig($i,$Iface) if ($ifDescr[$i] = $Iface);
if ($Addr = $ifNetAddr{$Iface}) {
$ipAdEntIfIndex{$Addr} = $atIfIndex{$Addr} = $i;
}
$ifMtu[$i] = $MTU;
$ifInPkts[$i] = $RX_OK;
$ifOutPkts[$i] = $TX_OK;
$ifInErrors[$i] = $RX_ERR;
$ipInReceives += $RX_OK + $RX_ERR + $RX_DRP + $RX_OVR;
$ifOutErrors[$i] = $TX_ERR;
$ifInDiscards[$i] = $RX_Drp;
$ifOutDiscards[$i] = $TX_Drp;
$ipOutRequests += $TX_OK + $TX_ERR + $TX_DRP + $TX_OVR;
print "
#iftbl ifconfig for $Iface done.\n" if $D>2;
} elsif (($Iface,$MTU,$Net,$Addr,$Ipkts,$Ierrs,$Opkts,$Oerrs)
= ($ifnt =~ $ifpat4)) {
++$i;
print "
#iftbl i=$i matched ifpat4.\n" if $D>2;
$ifIndex[$i] = $ifIndex{$Iface} = $i;
$ipAdEntIfIndex{$Addr} = $atIfIndex{$Addr} = $i if $Addr;
$ifDescr[$i] = $Iface;
$ifMtu[$i] = $MTU;
$ipInReceives += ($ifInPkts[$i] = $Ipkts);
$ipOutRequests += ($ifOutPkts[$i] = $Opkts);
$ifInErrors[$i] = $Ierrs;
$ifOutErrors[$i] = $Oerrs;
&ifconfig($i,$ifDescr[$i]) if ($ifDescr[$i]);
print "
#iftbl ifconfig for $Iface done.\n" if $D>2;
}
print "
#iftbl Done with $ifnt\n" if $D>2;
}
$cnt{'ipAd'} = $ipAddrs = $i;
$cnt{'if'} = $ifNumber = $i;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub iptbl {
print "
#iptbl ...\n" if $D>1;
&rttbl() if !$ipRoutes;
++$cnt{'ip'};
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# On linux, the file /proc/net/snmp contains useful SNMP data.
sub proc_snmp {
local(*a,$data,$file,$i,$line,$p,$v,@v,$n,@n,$x);
if (open(SNMP,'/proc/net/snmp')) {
for $line () {
if (($p,$data) = ($line =~ /^(\w+):\s+(.*)/)) {
$p =~ tr/A-Z/a-z/;
if (!$n{$p}) {
$n{$p} = $data; # Remember the list of variables.
} else { # values ...
$v{$p} = $data; # Remember the list of values.
@n = split(/\s+/,$n{$p});
@v = split(/\s+/,$v{$p});
for ($i = 0; $i <= $#n; $i ++) {
$n = @n[$i];
$v = @v[$i];
$V{"$p$n"} = $v;
*a = $_main{"$p$n"};
$a = $v; # Create global variable.
++$x;
print "\n" if $V>1;
}
}
}
}
} else {
print "
\n";
}
$x;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# rtnt Dest Addr Mask Flags M1 Ref Use Iface
$rtpat1 = "^($ipadp)\\s+($ipadp)\\s+($ipadp)\\s+(\\w+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\w+)\\s*\$";
# rtnt Dest Addr Flags Ref Use Iface
$rtpat2 = "^($ntadp)\\s+($ipadp)\\s+(\\w+)\\s+(\\d+)\\s+(\\d+)\\s+(\\w+)\\s*\$";
# rtnt Dest Addr Flags Ref Use Iface
$rtpat3 = "^(default)\\s+($ipadp)\\s+(\\w+)\\s+(\\d+)\\s+(\\d+)\\s+(\\w+)\\s*\$";
#
sub rttbl {
local(@rttb) = `netstat -rn`;
local($Dest,$Addr,$Mask,$Flags,$M1,$Ref,$Use,$Iface); # linux.
local($i);
print "
#rttbl ...\n" if $D>1;
&iftbl() if (!@ifIndex); # We'll need this to decode Iface.
# ipRouteDest ipRouteIfIndex ipRouteMetric1 ipRouteNextHop
for $rtnt (@rttb) {
if (($Dest,$Addr,$Mask,$Flags,$M1,$Ref,$Use,$Iface) = ($rtnt =~ $rtpat1)) { # Linux.
print "
#rttbl matched rtpat1.\n" if $D>2;
++$i;
$ipRouteDest{$Dest} = $Addr;
$ipRouteIfIndex{$Dest} = $ifIndex{$Iface};
$ipRouteMetric1{$Dest} = $M1;
$ipRouteNextHop{$Dest} = $Dest;
$ipRouteType{$Dest} = $Flags;
} elsif (($Dest,$Addr,$Flags,$Ref,$Use,$Iface) = ($rtnt =~ $rtpat2)) { # Ultrix.
print "
#rttbl matched rtpat2.\n" if $D>2;
++$i;
while (!($Dest =~ $ipadp)) {$Dest .= '.0'}
$ipRouteDest{$Dest} = $Addr;
$ipRouteIfIndex{$Dest} = $ifIndex{$Iface};
$ipRouteNextHop{$Dest} = $Dest;
$ipRouteType{$Dest} = $Flags;
} elsif (($Dest,$Addr,$Flags,$Ref,$Use,$Iface) = ($rtnt =~ $rtpat3)) { # Ultrix.
print "
#rttbl matched rtpat3.\n" if $D>2;
$Dest = '0.0.0.0';
++$i;
$ipRouteDest{$Dest} = $Addr;
$ipRouteIfIndex{$Dest} = $ifIndex{$Iface};
$ipRouteNextHop{$Dest} = $Dest;
$ipRouteType{$Dest} = $Flags;
} else {
print "
#rttbl Ignore $rtnt" if $D>2;
}
}
$cnt{'ipRoute'} = $ipRoutes = $i;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub tcpinfo {
&tcptbl();
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
$plinux="^tcp\\s+(-*\\d+)\\s+(-*\\d+)\\s+($ipadp):(\\d+)\\s+($ipadp):(\\d+)\\s+(\\w+)\\s+(\\w+)";
$pultrix = "^tcp\\s+(-*\\d+)\\s+(-*\\d+)\\s+($ipadp)\\.(\\d+)\\s+($ipadp)\\.(\\d+)\\s+(\\w+)";
#
sub tcptbl {
local($tcpnt,$i,$n);
local(@tcptb) = `netstat -an`;
local($Proto,$RecvQ,$SendQ,$LAddr,$LPort,$FAddr,$FPort,$State,$User);
print "
#tcptbl ...\n" if $D>1;
$tcpActiveOpens = $tcpCurrEstab = 0;
# tcpnt Proto RecvQ SendQ LAddr LPort FAddr FPort State User
for $tcpnt (@tcptb) {
$tcpnt =~ s/ \*\./ 0.0.0.0./g;
$tcpnt =~ s/\.\* /.0 /g;
if (
(($RecvQ,$SendQ,$LAddr,$LPort,$FAddr,$FPort,$State,$User) = ($tcpnt =~ m/$plinux/))
|| (($RecvQ,$SendQ,$LAddr,$LPort,$FAddr,$FPort,$State ) = ($tcpnt =~ m/$pultrix/))
) {
print "
#tcptbl Got tcp line.\n" if $D>2;
$i = "$LAddr.$LPort.$FAddr.$FPort";
++$n;
$tcpConnTable{$i} = 1; # List of keys.
$tcpConnLocalAddress{$i} = $LAddr;
$tcpConnRemAddress{$i} = $FAddr;
$tcpConnLocalPort{$i} = $LPort;
$tcpConnRemPort{$i} = $FPort;
if ($State eq LISTEN) {
$tcpConnState{$i} = 2;
++$tcpActiveOpens;
print "
# tcpActiveOpens=$tcpActiveOpens\n" if $D>2;
} elsif ($State eq CLOSE_WAIT) {
$tcpConnState{$i} = 10;
} elsif ($State eq ESTABLISHED) {
$tcpConnState{$i} = 5;
++$tcpActiveOpens;
++$tcpCurrEstab;
print "
# tcpCurrEstab=$tcpCurrEstab\n" if $D>2;
} else {
$tcpConnState{$i} = 0;
}
}
}
$cnt{'tcpConn'} = $tcpConnNumber = $n;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
sub usrtbl {
local($usrnt,$i);
local($Name,$Pswd,$Uid,$Gid,$Quota,$Cmnt,$Descr,$Home,$Shell,$Plan);
# Name Pswd Uid Gid Quota Cmnt Descr Home Shell
print "
#usrtbl ...\n" if $D>1;
while (($Name,$Pswd,$Uid,$Gid,$Quota,$Cmnt,$Descr,$Home,$Shell) = getpwent) {
++$i;
print "
#usrtbl i=$i usr $Name.\n" if $D>2;
$usrIndex[$i] = $i;
$usrName[$i] = $Name;
$usrUid[$i] = $Uid;
$usrGid[$i] = $Gid;
$usrDescr[$i] = "$Cmnt $Descr";
$usrHome[$i] = $Home;
$usrShell[$i] = $Shell;
if (open(P,"$Home/.plan")) {
@Plan = ;
$usrPlan[$i] = join("\t
",@Plan);
close P;
}
}
$cnt{'usr'} = $usrNumber = $i;
}
1;