Skip to content

Commit

Permalink
Added(utils): nic-model-list - show models of network cards. (#216)
Browse files Browse the repository at this point in the history
* Added(utils): nic-model-list - show models of network cards.
* Incremented version
  • Loading branch information
strizhechenko committed Dec 24, 2018
1 parent db2a0e5 commit 1e75627
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read(*paths):

setuptools.setup(
name='netutils-linux',
version='2.7.10',
version='2.7.11',
author='Oleg Strizhechenko',
author_email='[email protected]',
license='MIT',
Expand Down
50 changes: 50 additions & 0 deletions utils/nic-model-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

set -eu
# echo "$0 $@ [$$] START" >&2
declare DEVICE_REGEX="(eth|em|en|bond|p[0-9]*p)[0-9\.]+"

if [ "{1:-}" == '--help' ]; then
echo "Info: $0 показывает модели сетевых карт в системе"
echo "Usage: $0 без параметров"
echo "Example: $0"
exit 0
fi

rx_buf() {
ethtool -g "$1" 2>/dev/null | tac | grep "RX:" | egrep -o "[0-9]+" | tr '\n' '/'| sed 's|/$||g'
return 0
}

show_device() {
local eth="$1"
local id="$2"
is_vlan=0
if ethtool -i "$eth" | grep -q '802.1Q VLAN Support'; then
is_vlan=1
fi
if [ "$is_vlan" = 0 ]; then

echo "$eth: $(grep -w $id /tmp/lspci.tmp) rx: $(rx_buf "$eth")"
else
echo "$eth: VLAN interface"
fi
return 0
}

main() {
local eth
local id
for eth in $(egrep -o "$DEVICE_REGEX" /proc/net/dev | sort -u); do
for id in $(ethtool -i "$eth" | grep bus-info | sed 's/.*0000:https://'); do
show_device "$eth" "$id"
done
done
return 0
}

lspci > /tmp/lspci.tmp
main

# echo "$0 $@ [$$] SUCCESS"
exit 0

0 comments on commit 1e75627

Please sign in to comment.