forked from githubuser0xFFFF/URSim_Install_Guides
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed typos, added net-statistics perl script
- Loading branch information
1 parent
2a0cc2c
commit 9053dd7
Showing
2 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/perl | ||
|
||
# Replace eth1 with your right network interface | ||
my $interface = "eth1"; | ||
my $isDhcp = 0; | ||
my $isStatic = 0; | ||
|
||
open(INTF,"</etc/network/interfaces") || die "Cannot open interfaces"; | ||
while($line = <INTF>) { | ||
chomp $line; | ||
if ($line =~/eth0/) { | ||
$interface = "eth0" | ||
} | ||
if ($line =~ /$interface.*dhcp/) { | ||
$isDhcp = 1; | ||
} elsif ($line =~ /$interface.*static/) { | ||
$isStatic = 1; | ||
} | ||
} | ||
close INTF; | ||
|
||
my $interface_operstate = `cat /sys/class/net/$interface/operstate`; | ||
my @ifconfig = split(/\n/,`/sbin/ifconfig $interface 2>&1`); | ||
|
||
my $addr = ""; | ||
my $mask = ""; | ||
my $ifconfig_str = join(" ", @ifconfig); | ||
my $isNetDown = 1; | ||
|
||
|
||
if ($interface_operstate =~ /up/) { | ||
$isNetDown = 0; | ||
} | ||
|
||
if ($isDhcp) { | ||
print "Mode:dhcp\n"; | ||
} elsif ($isStatic) { | ||
print "Mode:static\n"; | ||
} else { | ||
print "Mode:disabled\n"; | ||
} | ||
|
||
if ($isNetDown) { | ||
print "Net down\n"; | ||
} else { | ||
print "Net up\n"; | ||
} | ||
|
||
|
||
foreach $line (@ifconfig) { | ||
chomp $line; | ||
if($line =~ /inet addr/) { | ||
$addr = $line; | ||
$addr =~ s/.*inet addr:([^ ]*).*/$1/; | ||
} | ||
if($line =~ /Mask/) { | ||
$mask = $line; | ||
$mask =~ s/.*Mask:([^ ]*).*/$1/; | ||
} | ||
} | ||
|
||
my @route = split(/\n/,`/sbin/route -n`); | ||
my $gateway = ""; | ||
foreach $line (@route) { | ||
chomp $line; | ||
if($line =~ /^0.0.0.0 /) { | ||
$gateway = $line; | ||
$gateway =~ s/^0.0.0.0[ ]*([^ ]*).*/$1/; | ||
} | ||
} | ||
|
||
open RES, "</etc/resolv.conf"; | ||
my @nameservers; | ||
while($line = <RES>) { | ||
chomp $line; | ||
if($line =~ /nameserver/) { | ||
my $name=$line; | ||
$name =~ s/nameserver //; | ||
push @nameservers, $name; | ||
} | ||
} | ||
close RES; | ||
|
||
my @hostname = split(/\n/, `hostname`); | ||
|
||
print "Address:$addr\n"; | ||
print "Mask:$mask\n"; | ||
print "Gateway:$gateway\n"; | ||
print "nameserver1:" . $nameservers[0] . "\n"; | ||
print "nameserver2:" . $nameservers[1] . "\n"; | ||
print "Hostname:$hostname[0]\n"; | ||
|
||
|
||
|
||
|