Skip to content

Commit

Permalink
Fixed typos, added net-statistics perl script
Browse files Browse the repository at this point in the history
  • Loading branch information
githubuser0xFFFF committed Mar 22, 2021
1 parent 2a0cc2c commit 9053dd7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ Using your bash prompt run the `/home/ur/ursim/install.sh` using the following c
sudo ./install.sh
```
If runit was installed properly before, the script should tun without any errors.
If runit was installed properly before, the script should run without any errors.
## Copy Libraries to /usr/bin
Since version 5.10 the extracted ursim folder contains the folder `usr/bin` with
executable files that should be installed to `/usr/bin` but which are not
touched by the install script. Therfor we need to copy the files manually from
touched by the provided install script. Therfore we need to copy the files manually from
the usrim folder to `/usr/bin`.
CD into your ursim folder and copy the files:
Expand Down Expand Up @@ -138,7 +138,8 @@ should output the following:
For proper network support ursim requires the perl script `/sbin/net-statistics`.
I'm not a linux expert and I have no idea where this file comes from so I
simply copied this file from the URSim Lubuntu 14.04 VM to my Ubuntu 16.04
installation. After you have copied the file, you should make it executable:
installation. I added the file to the repository `src` folder so you can take
it from there. After you have copied the file, you should make it executable:
```bash
sudo chmod u=rwx,g=rx,o=rx /sbin/net-statistics
Expand Down
95 changes: 95 additions & 0 deletions src/net-statistics
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";




0 comments on commit 9053dd7

Please sign in to comment.