[Fedora] General Linux Networking
Øyvind Lode
o-lode at online.no
Thu Jan 8 15:14:33 UTC 2004
At 01:29 08.01.2004, Bevan C. Bennett wrote:
>Bevan C. Bennett wrote:
> >
>>It would be relatively trivial to create a small script which gathers
>>that data, reformats it, and prints a Windows-like 'ipconfig' style summary.
>
>Just to prove that this is, in fact, possible... the following makes a
>passable imitation, for those interested in such things...
>
>#!/usr/bin/perl
>#
># 'ipconfig' like output - written as an experiment
># Jan 07, 2003 by Bevan Bennett (bevan at fulcrummicro.com)
>#
>
>open(IFINFO,'ifconfig|') || die "couldn't run ifconfig: $!\n";
>
>%interfaces = ();
>$current = "";
>$hostname = $ENV{"HOSTNAME"};
>
>while (<IFINFO>) {
> /^(\S+)\s+Link encap:Ethernet\s+HWaddr\s+(\S+)/ && do {
> $interfaces{$1}{"hwaddr"} = $2;
> $current = $1;
> next;
> };
> /^lo/ && do {
> $current = "";
> next;
> };
> next if (!$current);
> /inet addr:([\d\.]+)/ && do {$interfaces{$current}{"ipaddr"} = $1;};
> /Mask:([\d\.]+)/ && do {$interfaces{$current}{"mask"} = $1;};
>}
>close(IFINFO);
>
>open (DNSINFO,'/etc/resolv.conf') || die "Can't open /etc/resolv.conf: $!\n";
>while (<DNSINFO>) {
> /^domain (\S+)/ && do { $dnsdomain = $1; };
> /^search (.+)/ && do { @dnssearch = split / /,$1; };
> /^nameserver (\S+)/ && do { push @dnssrv,$1; };
>}
>close (DNSINFO);
>
>open (ROUTEINFO,'netstat -rn|') || die "Can't run netstat: $!\n";
>while (<ROUTEINFO>) {
> /0\.0\.0\.0\s+(\S+)\s+\S+\s+UG\s+\d+\s+\d+\s+\d+\s+(\S+)/ && do {
> $gateway = $1;
> $gateint = $2;
> };
>}
>close (ROUTEINFO);
>
>print "Fedora Core IP Configuration\n\n";
>print " Host Name . . . . . . . . . . . . . : " . $hostname . "\n";
>print " Primary DNS Suffix. . . . . . . . . : " . $dnsdomain . "\n";
>print " DNS Suffix Search List. . . . . . . : " . shift(@dnssearch)
>. "\n";
>while (@dnssearch) {
>print " " . shift(@dnssearch)
>. "\n";
>}
>print " DNS Servers . . . . . . . . . . . . : " . shift(@dnssrv) . "\n";
>while (@dnssrv) {
>print " " . shift(@dnssrv) . "\n";
>}
>print " Default Gateway . . . . . . . . . . : " . $gateway . " ("
> . $gateint . ")\n";
>print "\n";
>
>foreach $if (keys(%interfaces)) {
>print "Ethernet adapter Local Area Connection $if:\n\n";
>print " Physical Address. . . . . . . . . . : " .
>$interfaces{$if}{"hwaddr"} . "\n";
>print " IP Address. . . . . . . . . . . . . : " .
>$interfaces{$if}{"ipaddr"} . "\n";
>print " Subnet Mask . . . . . . . . . . . . : " .
>$interfaces{$if}{"mask"} . "\n";
>print "\n";
>}
>
Thanks everyone :-)
I have received many good inputs including this brilliant script.
Øyvind
>--
>fedora-list mailing list
>fedora-list at redhat.com
>To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list
>
More information about the fedora-list
mailing list