ServDoc_0205netbasics

Code Index:



NAME

ServDoc_0205netbasics - describe the network


VERSION

$Id: ServDoc_0205netbasics,v 1.14 2004/02/19 07:17:05 uherbst Exp $


SYNOPSIS

ServDoc_0205netbasics [-h|help] [-v|version] [--debug NETBASIC,intensity]


DESCRIPTION

ServDoc_0205netbasics tries to describe ALL important things about your network

Supported Systems

This module should work on

AIX
HP/UX
Solaris
Linux (RedHat and SuSE)

Things to describe - Network basics

Which interfaces
which addreses (MAC/IP/...)
routing
name resolution


OPTIONS

-h|help
This help.

-v|version
Version

--debug NETBASIC,intensity
Turn on Debugging for that module.

The debug feature for that module is named ``NETBASIC''.


AUTHORS

Ulrich Herbst <Ulrich.Herbst@gmx.de>


#!/usr/bin/perl -w

#----------------------------------------------------------------------

# standard perl modules
use strict;                       # print error about unknown variables ...
use English;                      # long internal variable names;
use FindBin;                      # In which directory is ServDoc itself ?
                                  # There has to be the module and the lib dir!
use lib $FindBin::Bin. "/lib";    # Here are the ServDoc-perl-modules
use vars qw($options);

# our own perl modules
use ServDoc;

#----------------------------------------------------------------------

$options->{Version} =
  '$Id: ServDoc_0205netbasics,v 1.14 2004/02/19 07:17:05 uherbst Exp $';

# We need the cmdline to call the modules with the same debug options.
$options->{cmdline} = join " ", @ARGV;

sub debug { ServDoc_debug( "NETBASIC", $options, shift, shift ); }

$options = &process_cmdline($options);

my $h='Net%%+Basics%%+';

%{$options->{lang}->{en}}=
  (
   netstat         => $h . 'All interfaces from netstat',
   netstat_short   => i18n_std('cmdout','netstat -i'),
   netstat_long    => '',

   ifconfig        => $h . 'All interfaces from ifconfig',
   netstat_short   => i18n_std('cmdout','ifconfig -a'),
   netstat_long    => '',

   ifconfighp      => $h . 'ifconfig%%+%s',
   ifconfighp_long => '',

   lanscan         => $h . 'lanscan',
   lanscan_short   => i18n_std('cmdout','lanscan -v'),
   lanscan_long    => '',

   mii             => $h . 'Interface Speed',
   mii_short       => i18n_std('cmdout','mii-tool'),
   mii_long        => '',

   routing         => $h . 'Routing',
   routing_short   => i18n_std('cmdout','netstat -rn'),
   routing_long    => 'The actual routing table',

   hostconf        => $h . 'Name resolution switch',
   hostconf_short  => i18n_std('filecontent','/etc/host.conf'),
   hostconf_long   => 'DNS or /etc/hosts ?',

   nsswitch        => $h . 'Name resolution switch',
   nsswitch_short  => i18n_std('filecontent','/etc/nsswitch.conf'),
   nsswitch_long   => 'DNS or /etc/hosts or NIS or LDAP or ... ?',

   hosts           => $h . 'Local Hosts-File',
   hosts_short     => i18n_std('filecontent','/etc/hosts'),
   hosts_long      => '',

   dns             => $h . 'DNS Client Configuration',
   dns_short       => i18n_std('filecontent','/etc/resolv.conf'),
   dns_long        => 'This file describe your Domain Name Server(s), ' .
   ' and your searchpath',

   ports           => $h . 'Open Ports',
   ports_short     => i18n_std('cmdout','netstat -a'),
   ports_long      => 'Which ports are open on your system ? It is a '.
   'good practice to close all unneeded ports (that is: to stop '.
   'the daemon processes).',

   forward         => $h . 'IP forwarding',
   forward_short   =>
   i18n_std('filecontent','/proc/sys/net/ipv4/ip_forward'),
   forward_long    => 'Does your server works as IP Router ?',
   forward_yes     => 'Routing (IP forwarding) enabled',
   forward_no      => 'Routing (IP forwarding) disabled',

   iptables        => $h . 'Firewall',
   iptables_short  => i18n_std('cmdout','iptables -L'),
   iptables_long   => 'Does a paket filter run on your server ?',
  );

$h='Netzwerk%%+Grundlagen%%+';
%{$options->{lang}->{de}}=
  (
   netstat         => $h . 'Alle Schnittstellen (netstat)',
   netstat_short   => i18n_std('cmdout','netstat -i'),
   netstat_long    => '',

   ifconfig        => $h . 'Alle Schnittstellen (ifconfig)',
   ifconfig_short  => i18n_std('cmdout','ifconfig -a'),
   ifconfig_long   => '',

   ifconfighp      => $h . 'ifconfig%%+%s',
   ifconfighp_long => '',

   lanscan         => $h . 'lanscan',
   lanscan_short   => i18n_std('cmdout','lanscan -v'),
   lanscan_long    => '',

   mii             => $h . 'Netzwerk-Geschwindigkeit',
   mii_short       => i18n_std('cmdout','mii-tool'),
   mii_long        => '',

   routing         => $h . 'Routing',
   routing_short   => i18n_std('cmdout','netstat -rn'),
   routing_long    => 'Die aktuelle Routing-Tabelle',

   hostconf        => $h . 'Namensaufl&ouml;sung',
   hostconf_short  => i18n_std('filecontent','/etc/host.conf'),
   hostconf_long   => 'DNS or /etc/hosts ?',

   nsswitch        => $h . 'Namensaufl&ouml;sung',
   nsswitch_short  => i18n_std('filecontent','/etc/nsswitch.conf'),
   nsswitch_long   => 'DNS or /etc/hosts or NIS or LDAP or ... ?',

   hosts           => $h . 'Lokale Hosts-Datei',
   hosts_short     => i18n_std('filecontent','/etc/hosts'),
   hosts_long      => '',

   dns             => $h . 'DNS Client Konfiguration',
   dns_short       => i18n_std('filecontent','/etc/resolv.conf'),
   dns_long        => 'Wo sind die Domain Name Server und wie '.
   ' sieht die Dom&auml;nensuchreihenfolge aus ?',

   ports           => $h . 'Offene Ports',
   ports_short     => i18n_std('cmdout','netstat -a'),
   ports_long      => 'Welche Ports sind auf diesem System offen ? '.
   'Oftmals schliesst man aus Sicherheitsgr&uuml;nden alle unbenutzten '.
   'Ports, indem man die zugeh&ouml;rigen Prozesse beendet.',

   forward         => $h . 'IP Paketweiterleitung',
   forward_short   =>
   i18n_std('filecontent','/proc/sys/net/ipv4/ip_forward'),
   forward_long    => 'Arbeitet dieser Server als Router f&uuml;r '.
   'IP-Pakete ?',
   forward_yes     => 'Routing (IP forwarding) eingeschaltet',
   forward_no      => 'Routing (IP forwarding) ausgeschaltet',

   iptables        => $h . 'Firewall',
   iptables_short  => i18n_std('cmdout','iptables -L'),
   iptables_long   => 'L&auml;uft auf diesem Server ein Paketfilter (Firewall) ?'
  );
debug( 9, i18n_std('running',$0));

#----------------------------------------------------------------------

# Main

# If we are not on HP/UX,Solaris, AIX, Linux, return silently.
if ( ! is_unix() ) {
  debug(1, i18n_std('unsupported','Basic Network Description'));
  exit 0;
}

#=item Which interfaces, which addresses

INTERFACES: {

  # All unixes know about netstat
  report_i18n('cmd','netstat','netstat -i');

 IFCONFIG: {
    if ( $OSNAME =~ /linux/ ) {
      #############################
      report_i18n('cmd','ifconfig','ifconfig');
      last;    # break out from IFCONFIG:

    } elsif ( $OSNAME =~ /aix/ ) {
      #############################
      report_i18n('cmd','ifconfig','ifconfig -a');
      last;    # break out from IFCONFIG:

    } elsif ( $OSNAME =~ /hpux/ ) {
      #############################
      # FIXME: We don't really need @netstat.
      my @netstat = grep !/Name/,
	            split /\n/,do_cmd("netstat -in");
      foreach my $interface (@netstat) {
	$interface =~ s/(.*?)\s+.*/$1/;
        report_cmd(i18n_mesg('ifconfighp',$1),
                   i18n_std('cmdout',"ifconfig $1"),
                   i18n_mesg('ifconfighp_long'),
                   "ifconfig $1");
      }
      report_i18n('cmd','lanscan','lanscan -v');
      last;    # break out from IFCONFIG:
    } elsif ( $OSNAME =~ /solaris/ ) {
      #############################
      report_i18n('cmd','ifconfig','ifconfig -a');
      last;    # break out from IFCONFIG:
    } elsif ($OSNAME =~ /darwin/) {
      report_i18n('cmd','ifconfig','ifconfig -a');
	last;
    } else {
      debug( 1, i18n_std('unsupported','IFCONFIG'));
    }
  }   # IFCONFIG:

 LANSPEED: {
    if ($OSNAME =~ /linux/) {
      report_i18n('cmd','mii','mii-tool', UID => 0);
      # If that's a system without mii-tool: null problemo, do_cmd
      # catches that error
    }

    # FIXME AIX: entstat
  }
}    # INTERFACES:

#=item routing
# Does that work for ALL supported unixes ?
report_i18n('cmd','routing','netstat -rn');

#=item name resolution
# - Which name resolution method to use ?
#   This one is tricky and VERY os-dependent!
NAME_RES: {
  if ( $OSNAME =~ /linux/ ) {

    # /etc/host.conf, /etc/nsswitch.conf
    report_i18n('file','hostconf','/etc/host.conf');
    report_i18n('file','nsswitch','/etc/nsswitch.conf');
    last NAME_RES;
  }
  # FIXME: Where are non-linux-systems ?

  debug( 1, i18n_std('unsupported','Name Resolution'));
}    # NAME_RES

# /etc/hosts
# Oh, that's easy, every server has that !
report_i18n('file','hosts','/etc/hosts');

# - DNS: which servers, which search-domains ?
# I think, that is os-independent, too
if ( -e "/etc/resolv.conf" ) {
  report_i18n('file','dns','/etc/resolv.conf');
}

# Which open ports ?
report_i18n('cmd','ports','netstat -a');

if ($OSNAME =~ /linux/ ) {
  # Is routing enabled ?
  my $string="Routing (IP forwarding) enabled";
  if ( readfile("/proc/sys/net/ipv4/ip_forward") eq 0 ) {
    report_i18n('string','forward',i18n_mesg('forward_no'));
  } else {
    report_i18n('string','forward',i18n_mesg('forward_yes'));
  }

  # iptables enabled ?
  if ( -r "/proc/net/ip_tables_names" ) {
    report_i18n('cmd','iptables','iptables -L');
  }
}