Make ruby ifconfig example output a bit closer to net-tools default - only

showing interfaces that are up and suppressing the output of unconfigured ip
addresses.
This commit is contained in:
Matthew Kent 2009-08-04 23:00:07 -07:00
parent 48f9f8cc65
commit 4e206baa61
1 changed files with 13 additions and 4 deletions

View File

@ -8,6 +8,10 @@ iflist.each do |ifname|
flags = ifconfig.flags flags = ifconfig.flags
encap = ifconfig.type encap = ifconfig.type
if (flags & Sigar::IFF_UP) == 0
next
end
hwaddr = ifconfig.hwaddr hwaddr = ifconfig.hwaddr
if hwaddr == Sigar::NULL_HWADDR if hwaddr == Sigar::NULL_HWADDR
hwaddr = "" hwaddr = ""
@ -29,8 +33,11 @@ iflist.each do |ifname|
bcast = "" bcast = ""
end end
puts "\t" + "inet addr:" + ifconfig.address + address = ifconfig.address
ptp + bcast + " Mask:" + ifconfig.netmask if address != "0.0.0.0"
puts "\t" + "inet addr:" + address +
ptp + bcast + " Mask:" + ifconfig.netmask
end
if ifconfig.prefix6_length != 0 if ifconfig.prefix6_length != 0
puts "\t" + "inet6 addr: " + ifconfig.address6 + "/" + puts "\t" + "inet6 addr: " + ifconfig.address6 + "/" +
@ -63,11 +70,13 @@ iflist.each do |ifname|
rx_bytes = ifstat.rx_bytes rx_bytes = ifstat.rx_bytes
tx_bytes = ifstat.tx_bytes tx_bytes = ifstat.tx_bytes
print "\t" + puts "\t" +
"RX bytes:" + rx_bytes.to_s + "RX bytes:" + rx_bytes.to_s +
" (" + Sigar.format_size(rx_bytes) + ")" + " (" + Sigar.format_size(rx_bytes) + ")" +
" " + " " +
"TX bytes:" + tx_bytes.to_s + "TX bytes:" + tx_bytes.to_s +
" (" + Sigar.format_size(tx_bytes) + ")" + "\n"; " (" + Sigar.format_size(tx_bytes) + ")" + "\n"
end end
puts "\n"
end end