Updated net-tools with fixes and license change
By joe
- 3 minutes read - 525 wordsIts been a while, I know. My apologies.
Ok, first off, I’ve been very busy at the $dayjob. More in a later post. But I’ve been doing some code fix up for a number of my tools, specifically the net-tools collection. This one had nagged me a long time.
Ok, here it is in a nutshell. The way lsnet worked, it used fixed sized columns for, unfortunately, variable sized fields.
Here is the way its been working for years.
<code>joe@bender:~$ lsnet.pl
DEVICE [ MASTER] LINK: IP Address MTU TX (bytes) RX (bytes)
br10 [ ] up: 192.168.5.240/24 1500 3.022 MB 207.193 MB
br10 [ ] up: fe80::225:90ff:fe2f:8c02/64 1500 3.022 MB 207.193 MB
br_int [ ] up: 10.100.0.1/16 1500 0.018 MB 0.000 MB
br_int [ ] up: fe80::a4ef:1ff:fea0:e789/64 1500 0.018 MB 0.000 MB
igb0 [ ] down: 1500 0.000 MB 0.000 MB
igb1 [ ] down: 1500 0.000 MB 0.000 MB
igb2 [ br10] up: 1500 3.023 MB 214.100 MB
igb3 [ ] down: 1500 0.000 MB 0.000 MB
lo [ ] up: 65536 0.027 MB 0.027 MB
lo [ ] up: ::1/128 65536 0.027 MB 0.027 MB
virbr0 [ ] down: 192.168.123.1/24 1500 0.000 MB 0.000 MB
virbr0-nic [ virbr0] down: 1500 0.000 MB 0.000 MB
</code>
As you can see, the formatting is messy. And I cant easily extract info from it in csv format.
So I spent some time cleaning up the code. Adding options. Lets see how the new code behaves
<code>joe@bender:~$ ./lsnet.pl
DEV [ MST] ST SP IP MTU TX RX
br10 [ ] up 192.168.5.240/24 1500 3.018 MB 206.944 MB
br10 [ ] up fe80::225:90ff:fe2f:8c02/64 1500 3.018 MB 206.944 MB
br_int [ ] up 10.100.0.1/16 1500 18.362 kB 0
br_int [ ] up fe80::a4ef:1ff:fea0:e789/64 1500 18.362 kB 0
igb0 [ ] down 1500 0 0
igb1 [ ] down 1500 0 0
igb2 [ br10] up 1Gb 1500 3.019 MB 213.844 MB
igb3 [ ] down 1500 0 0
lo [ ] up 127.0.0.1/8 65536 26.733 kB 26.733 kB
lo [ ] up ::1/128 65536 26.733 kB 26.733 kB
virbr0 [ ] down 192.168.123.1/24 1500 0 0
virbr0-nic [virbr0] down 1500 0 0
</code>
So now the TX and RX (transmit/receive) bytes are autoscaled properly. The status shows up or down. The Speed shows physical adapter current speed.
We can also look at just one interface
<code>joe@bender:~$ ./lsnet.pl -i br10
DEV [MST] ST SP IP MTU TX RX
br10 [] up 192.168.5.240/24 1500 3.027 MB 207.864 MB
br10 [] up fe80::225:90ff:fe2f:8c02/64 1500 3.027 MB 207.864 MB
</code>
or two … or N
<code>joe@bender:~$ ./lsnet.pl -i br10,br_int
DEV [MST] ST SP IP MTU TX RX
br10 [] up 192.168.5.240/24 1500 3.029 MB 207.977 MB
br10 [] up fe80::225:90ff:fe2f:8c02/64 1500 3.029 MB 207.977 MB
br_int [] up 10.100.0.1/16 1500 18.362 kB 0
br_int [] up fe80::a4ef:1ff:fea0:e789/64 1500 18.362 kB 0
</code>
We can output this in CSV format
<code>joe@bender:~$ ./lsnet.pl -i br10,br_int -csv
#Device,Master,State,Speed,IP,MTU,TX,RX
br10,,up,,192.168.5.240/24,1500,3.031 MB,208.161 MB
br10,,up,,fe80::225:90ff:fe2f:8c02/64,1500,3.031 MB,208.161 MB
br_int,,up,,10.100.0.1/16,1500,18.362 kB,0
br_int,,up,,fe80::a4ef:1ff:fea0:e789/64,1500,18.362 kB,0
</code>
I still have some cleanup to do, but this has been pushed out to the repository.
Sometimes, its the little victories that make this all work nicely.