From c7079c5f00c7a2cd405073dd37324b01a8e8ccc3 Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Mon, 25 Apr 2011 06:23:41 +0000 Subject: [PATCH] new feature, in stable trunk, -n, shows advanced network card information. This will probably be modified quite a bit over time so it's a 1.4.80 to start, once it's stable, it will be 1.5.0 release. --- inxi | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 6 deletions(-) diff --git a/inxi b/inxi index 34d4bb3..df64bb8 100755 --- a/inxi +++ b/inxi @@ -1,8 +1,8 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 1.4.24 -#### Date: April 20 2011 +#### version: 1.4.80 +#### Date: April 24 2011 ######################################################################## #### SPECIAL THANKS ######################################################################## @@ -223,6 +223,7 @@ B_ROOT='false' B_RUNNING_IN_SHELL='false' # this sets the debug buffer B_SCRIPT_UP='false' +B_SHOW_ADVANCED_NETWORK='false' # Show sound card data B_SHOW_AUDIO='false' B_SHOW_CPU='false' @@ -1054,7 +1055,7 @@ get_parameters() # the short form only runs if no args output args are used # no need to run through these if there are no args if [[ -n $1 ]];then - while getopts Ac:CdDfFGhHiIlNopPrsSt:uv:Vx%@:${update_flags} opt + while getopts Ac:CdDfFGhHiIlnNopPrsSt:uv:Vx%@:${update_flags} opt do case $opt in A) B_SHOW_AUDIO='true' @@ -1105,6 +1106,11 @@ get_parameters() B_SHOW_PARTITIONS='true' use_short='false' ;; + n) B_SHOW_ADVANCED_NETWORK='true' + B_SHOW_NETWORK='true' + B_EXTRA_DATA='true' + use_short='false' + ;; N) B_SHOW_NETWORK='true' use_short='false' ;; @@ -1270,7 +1276,8 @@ show_options() print_screen_output " Not shown with -F for user security reasons, you shouldn't paste your local/wan IP." print_screen_output "-I Show Information: processes, uptime, memory, irc client, inxi version." print_screen_output "-l Show partition labels. Default: short partition -P. For full -p output, use: -pl (or -plu)." - print_screen_output "-N Show Network card information." + print_screen_output "-n Show Advanced Network card information. Same as -Nnx. Shows interface, speed, mac id, state, etc." + print_screen_output "-N Show Network card information. With -x, shows PCI BusID, Port number." print_screen_output "-o Show unmounted partition information (includes UUID and LABEL if available)." print_screen_output " Shows file system type if you have file installed, if you are root OR if you have" print_screen_output " added to /etc/sudoers (sudo v. 1.7 or newer): ALL = NOPASSWD: /usr/bin/file (sample)" @@ -3017,7 +3024,55 @@ get_networking_data() } }') ) IFS="$ORIGINAL_IFS" + if [[ $B_SHOW_ADVANCED_NETWORK == 'true' ]];then + get_network_advanced_data + fi log_function_data "A_NETWORK_DATA: ${A_NETWORK_DATA[@]}" + + eval $LOGFE +} + +get_network_advanced_data() +{ + eval $LOGFS + local a_network_adv_working='' card_port='' working_path='' + local eth_id='' speed='' duplex='' mac_id='' oper_state='' + + for (( i=0; i < ${#A_NETWORK_DATA[@]}; i++ )) + do + IFS="," + a_network_adv_working=( ${A_NETWORK_DATA[i]} ) + working_path="/sys/bus/pci/devices/0000:${a_network_adv_working[4]}" + if [[ -e $working_path/net ]];then + card_port=$( ls $working_path/net 2>/dev/null ) + eth_id=$card_port + working_path=$working_path/net/$card_port + # 2.6.32 debian lenny kernel shows not: /net/eth0 but /net:eth0 + else + card_port=$( ls $working_path | grep 'net:' ) + eth_id=$( cut -d ':' -f 2 <<< "$card_port" ) + working_path=$working_path/$card_port + fi + + if [[ -n $card_port ]];then + if [[ -f $working_path/speed ]];then + speed=$( cat $working_path/speed ) + fi + if [[ -f $working_path/duplex ]];then + duplex=$( cat $working_path/duplex ) + fi + if [[ -f $working_path/address ]];then + mac_id=$( cat $working_path/address ) + fi + if [[ -f $working_path/operstate ]];then + oper_state=$( cat $working_path/operstate ) + fi + fi + + A_NETWORK_DATA[i]=${a_network_adv_working[0]}","${a_network_adv_working[1]}","${a_network_adv_working[2]}","${a_network_adv_working[3]}","${a_network_adv_working[4]}","$eth_id","$oper_state","$speed","$duplex","$mac_id + IFS="$ORIGINAL_IFS" + done + eval $LOGFE } @@ -4809,6 +4864,7 @@ print_networking_data() network_data="${C1}$card_one${C2} ${a_network_working[0]}$driver_data$port_data$pci_bus_id" network_data=$( create_print_line "Network:" "$network_data" ) print_screen_output "$network_data" + print_network_advanced_data "${a_network_working[4]}" i=0 ## loop starts with 1 by auto-increment so it only shows cards > 1 while [[ -n ${A_NETWORK_DATA[++i]} ]] do @@ -4837,7 +4893,9 @@ print_networking_data() fi network_data="${C1}Card-$(( $i + 1 ))${C2} ${a_network_working[0]}$driver_data$port_data$pci_bus_id" network_data=$( create_print_line " " "$network_data" ) + print_screen_output "$network_data" + print_network_advanced_data "${a_network_working[4]}" done fi if [[ $B_SHOW_IP == 'true' ]];then @@ -4846,6 +4904,37 @@ print_networking_data() eval $LOGFE } +# args: $1 - pci bus id +print_network_advanced_data() +{ + eval $LOGFS + local network_data='' eth_id='N/A' duplex='N/A' mac_id='N/A' speed='N/A' oper_state='N/A' + + if [[ $B_SHOW_ADVANCED_NETWORK == 'true' ]];then + if [[ -n ${a_network_working[5]} ]];then + eth_id=${a_network_working[5]} + fi + if [[ -n ${a_network_working[6]} ]];then + oper_state=${a_network_working[6]} + fi + if [[ -n ${a_network_working[7]} ]];then + speed="${a_network_working[7]} Mbps" + fi + if [[ -n ${a_network_working[8]} ]];then + duplex=${a_network_working[8]} + fi + if [[ -n ${a_network_working[9]} ]];then + mac_id=${a_network_working[9]} + fi + network_data="${C1}IF:${C2} $eth_id ${C1}State:${C2} $oper_state ${C1}Speed:${C2} $speed" + network_data="$network_data ${C1}Duplex:${C2} $duplex ${C1}Mac:${C2} $mac_id" + network_data=$( create_print_line " " "$network_data" ) + print_screen_output "$network_data" + fi + + eval $LOGFE +} + print_networking_ip_data() { eval $LOGFS @@ -4867,12 +4956,12 @@ print_networking_ip_data() IFS="$ORIGINAL_IFS" if [[ $i -lt 3 ]];then if [[ -n ${a_interfaces_working[0]} ]];then - interfaces="$interfaces ${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]}" + interfaces="$interfaces ${a_interfaces_working[0]} ${C1}IP:${C2} ${a_interfaces_working[1]}" fi else if [[ -n ${a_interfaces_working[0]} ]];then # space on end here for lining up with line starter - interfaces_2="$interfaces_2${C1}${a_interfaces_working[0]}${C2} ${a_interfaces_working[1]} " + interfaces_2="$interfaces_2${a_interfaces_working[0]} ${C1}IP:${C2} ${a_interfaces_working[1]} " fi fi ((i++))