netinfo - Read Network & PC Information into a Local Text File

I have come up with another script that looks at your network and hardware setup, creating a text file in your Document folder. This information could be useful to provide to others in the event of a problem or for your own information. The core of the script came from nixCraft, which can be found at Bash Shell Scripting Directory For Linux / UNIX. I made some modifications for use with openSUSE. These include saving the information text file in your home/user/Documents folder in the format network.DD-MM-YY.info.txt. Running the script file more than once a day just keeps over writing the file for any date, but would create a new file on each separate date that it is run.

To create this file, copy and paste the following text into your favorite text editor and save it in your home bin folder (~/bin) as the file netinfo.

#!/bin/bash

#: Title       : netinfo
#: Date Created: Jun-03-2009
#: Last Edit   : Tue Oct 12 19:21:32 CDT 2010
#: Author      : nixCraft, Edited by j. McDaniel
#: Version     : 1.00
#: Description : Reads Network & PC Info into a Text File
#: Options     : None, Start netinfo as a Standard User

# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------

# Modified for use on the openSUSE Forums on October 12, 2010

#
# Location to put information File.
#

DOC=~/Documents

#
# Check to see if we are root, Do not run as root since we need save the USER name.
#

tput clear
if  $UID -ne 0 ]]; then
  echo "Root User Permissions are required, Please Enter the ..."
  echo
  sudo $0 $DOC $USER
  exit 0
fi

echo
echo "netinfo - Read Network & PC Information into a Local Text File"
echo 

DOC=$1
OWNER=$2
HWINF=/usr/sbin/hwinfo
IFCFG=/sbin/ifconfig
IP4FW=/usr/sbin/iptables
IP6FW=/usr/sbin/ip6tables
LSPCI=/sbin/lspci
ROUTE=/sbin/route
NETSTAT=/bin/netstat
LSB=/usr/bin/lsb_release
 
## files ##
DNSCLIENT="/etc/resolv.conf"
DRVCONF="/etc/modprobe.conf"
NETALIASCFC="/etc/sysconfig/network-scripts/ifcfg-eth?-range?"
NETCFC="/etc/sysconfig/network-scripts/ifcfg-eth?"
NETSTATICROUTECFC="/etc/sysconfig/network-scripts/route-eth?"
SYSCTL="/etc/sysctl.conf"
 
## Output file ##
OUTPUT=$DOC"/network.$(date +'%d-%m-%y').info.txt"
 
## Email info to?? ##
SUPPORT_ID="you@example.com"
 
chk_root(){
    local meid=$(id -u)
    if  $meid -ne 0 ];
    then
        echo "You must be root user to run this tool"
        exit 999
    fi
}
 
write_header(){
    echo "---------------------------------------------------" >> $OUTPUT
    echo "$@" >> $OUTPUT
    echo "---------------------------------------------------"  >> $OUTPUT
}
 
dump_info(){
    echo "* Hostname: $(hostname)" >$OUTPUT
    echo "* Run date and time: $(date)" >>$OUTPUT
 
    write_header "Linux Distro"
    echo "Linux kernel: $(uname -mrs)" >>$OUTPUT
    $LSB -a >> $OUTPUT    
 
     -x ${HWINF} ] && write_header "${HWINF} --network_ctrl"
     -x ${HWINF} ] && ${HWINF} --network_ctrl >> $OUTPUT
 
     -x ${HWINF} ] && write_header "${HWINF} --isapnp"
     -x ${HWINF} ] && ${HWINF} --isapnp >> $OUTPUT
 
    write_header "PCI Devices"
    ${LSPCI} -v >> $OUTPUT
 
    write_header "$IFCFG Output"
    $IFCFG >> $OUTPUT
 
    write_header "Kernel Routing Table"
    $ROUTE -n >> $OUTPUT
 
    write_header "Network Card Drivers Configuration $DRVCONF"
     -f $DRVCONF ] && grep eth $DRVCONF  >> $OUTPUT || echo "Error $DRVCONF file not found."  >> $OUTPUT
 
    write_header "DNS Client $DNSCLIENT Configuration"
     -f $DNSCLIENT ] && cat $DNSCLIENT >> $OUTPUT || echo "Error $DNSCLIENT file not found." >> $OUTPUT
 
    write_header "Network Configuration File"
    for f in $NETCFC
    do
        if  -f $f ]
        then
            echo "** $f **" >> $OUTPUT
            cat $f >> $OUTPUT
        else
            echo "Error $f not found." >> $OUTPUT
        fi
    done 
 
    write_header "Network Aliase File"
    for f in $NETALIASCFC
    do
        if  -f $f ]
        then
            echo "** $f **" >> $OUTPUT
            cat $f >> $OUTPUT
        else
            echo "Error $f not found." >> $OUTPUT
        fi
    done 
 
    write_header "Network Static Routing Configuration"
    for f in $NETSTATICROUTECFC
    do
        if  -f $f ]
        then
            echo "** $f **" >> $OUTPUT
            cat $f >> $OUTPUT
        else
            echo "Error $f not found." >> $OUTPUT
        fi
    done 
 
    write_header "IP4 Firewall Configuration"
    $IP4FW -L -n >> $OUTPUT
 
    write_header "IP6 Firewall Configuration"
    $IP6FW -L -n  >> $OUTPUT
 
    write_header "Network Stats"
    $NETSTAT -s >> $OUTPUT
 
    write_header "Network Tweaks via $SYSCTL"
     -f $SYSCTL ] && cat $SYSCTL >> $OUTPUT || echo "Error $SYSCTL not found." >>$OUTPUT
 
#
# Change Owner of Text File from root to User
#    
    chown $OWNER:users $OUTPUT

#
# Display Information about Using the Less command to view Text Fie
#

    echo
    echo "Your Network and PC Information Text File Has Been Created.  Your Text File will"
    echo "be loaded for viewing using the Less command..........Just Press Q to Quit Less."
    echo
    read -p "Please Press <enter> to continue..."

    less $OUTPUT

    echo
    echo "The Network Configuration Info was Written To the file: $OUTPUT."
    echo
}
 
chk_root
dump_info

exit 0
# End Of Script


To make the script file executable, open a terminal session and execute the following command:

chmod +x ~/bin/netinfo

To use the netinfo script, open another terminal session and simply type netinfo at the terminal prompt with NO RUN TIME OPTIONS. You must be a standard user, do not run as root so that your user name and home area can be saved. The root user password will then be requested, the network and pc information acquired and the text file created for you. Since the text file is created while you are root, the text file is changed from being owned by root to be owned by the standard user that started the script file using the chown command, towards the end of the script.

Thank You,

Very nice:) found a few errors so now I might be able to fix them.

Thanks

brad455 Very nice:) found a few errors so now I might be able to fix them.

Thanks
Yes, let us know what you found. Since the core program came from someone else, errors running on openSUSE are possible. Anything you have found would be good to know.

Thank You,

Since the core program came from someone else, errors running on openSUSE are possible. Anything you have found would be good to know.

Oh so you didn’t test it out before you posted it? LOL

These are the errors I found now they might be my fault or I have not set some thing up.

Error /etc/modprobe.conf file not found.

Error /etc/sysconfig/network-scripts/ifcfg-eth? not found.

Error /etc/sysconfig/network-scripts/ifcfg-eth?-range? not found.

Error /etc/sysconfig/network-scripts/route-eth? not found.

You can eliminate one error by changing NETCFC as follows. Not sure about the other ones. It is getting late here. I will look at it further on Wednesday.

NETCFC="/etc/sysconfig/network/ifcfg-eth?"

Thank You,

I was looking at the script and the folders where the script is pointing to.

NETALIASCFC="/etc/sysconfig/network-scripts/ifcfg-eth?-range?"
I do not have this under this folder.

NETCFC="/etc/sysconfig/network/ifcfg-eth?"
I do not have this under this folder.

NETSTATICROUTECFC="/etc/sysconfig/network-scripts/route-eth?"
I do not have this under this folder.

HWINF=/usr/sbin/hwinfo
IFCFG=/sbin/ifconfig
IP4FW=/usr/sbin/iptables
IP6FW=/usr/sbin/ip6tables
LSPCI=/sbin/lspci
ROUTE=/sbin/route
NETSTAT=/bin/netstat
LSB=/usr/bin/lsb_release

Of those commands, only the iptables commands need root permission to run. Perhaps it might be more prudent to run the others as a normal user.

This is normal. /etc/sysconfig/network-scripts is on Fedora, not on openSUSE

Either you didn’t configure your network with the (preferred) ifup method or you don’t have wired network device.

Same as in 1

lspci -v displays infos about all pci devices. If you’re only interested in network devices, maybe something like:
lspci -v | grep -i -A 7 -e ‘Network controller’ -e 'Ethernet controller’
or even better:
lshw -class network

However I’m not sure lshw is installed by default.

It is not on openSUSE, but /usr/sbin/hwinfo is.

However, this script reminded me of something that already exists and does a lot more than only displaying stuff.

I suspect the idea behind this script is to give information about what might be the problem if network does not work as expected, this is exactly where this baby enters the stage.

collectNWData Überblick / Overview | collectNWData.sh

You might take that script to get some ideas about what you still missed or -even better- contact the author if you have some of your ideas implemented in the collectNWdata-script still not present there (although I didn’t find anything in your script yet).

For example, this here is not really good:

NETALIASCFC="/etc/sysconfig/network-scripts/ifcfg-eth?-range?"

What about all types of (especially wireless) interfaces not called ethX?

What about if somebody uses NetworkManager and therefore doesn’t have such files (they are not needed and in some cases even cause trouble if they exist)?

So I have removed three items being looked for that do not exist in openSUSE, but I am leaving the ‘NETCFC="/etc/sysconfig/network/ifcfg-eth?"’ as you could have this if you use ifup.

#!/bin/bash

#: Title       : netinfo
#: Date Created: Jun-03-2009
#: Last Edit   : Tue Oct 12 19:21:32 CDT 2010
#: Author      : nixCraft, Edited by j. McDaniel
#: Version     : 1.10
#: Description : Reads Network & PC Info into a Text File
#: Options     : None, Start netinfo as a Standard User

# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------

# Modified for use on the openSUSE Forums on October 12, 2010

#
# Location to put information File, Save Home Area Before Becoming Root
#

DOC=~/Documents

#
# Check to see if we are root, Do not run as root since we need save the USER name.
#

tput clear
if  $UID -ne 0 ]]; then
  echo "Root User Permissions are required, Please Enter the ..."
  echo
  sudo $0 $DOC $USER
  exit 0
fi

echo
echo "netinfo 1.10 - Read Network & PC Information into a Local Text File"
echo 

DOC=$1
OWNER=$2
HWINF=/usr/sbin/hwinfo
IFCFG=/sbin/ifconfig
IP4FW=/usr/sbin/iptables
IP6FW=/usr/sbin/ip6tables
LSPCI=/sbin/lspci
ROUTE=/sbin/route
NETSTAT=/bin/netstat
LSB=/usr/bin/lsb_release
 
## files ##
DNSCLIENT="/etc/resolv.conf"
NETCFC="/etc/sysconfig/network/ifcfg-eth?"
SYSCTL="/etc/sysctl.conf"
 
## Output file ##
OUTPUT=$DOC"/network.$(date +'%d-%m-%y').info.txt"
 
## Email info to?? ##
SUPPORT_ID="you@example.com"
 
chk_root(){
    local meid=$(id -u)
    if  $meid -ne 0 ];
    then
        echo "You must be root user to run this tool"
        exit 999
    fi
}
 
write_header(){
    echo "---------------------------------------------------" >> $OUTPUT
    echo "$@" >> $OUTPUT
    echo "---------------------------------------------------"  >> $OUTPUT
}
 
dump_info(){
    echo "* Hostname: $(hostname)" >$OUTPUT
    echo "* Run date and time: $(date)" >>$OUTPUT
 
    write_header "Linux Distro"
    echo "Linux kernel: $(uname -mrs)" >>$OUTPUT
    $LSB -a >> $OUTPUT    
 
     -x ${HWINF} ] && write_header "${HWINF} --network_ctrl"
     -x ${HWINF} ] && ${HWINF} --network_ctrl >> $OUTPUT
 
     -x ${HWINF} ] && write_header "${HWINF} --isapnp"
     -x ${HWINF} ] && ${HWINF} --isapnp >> $OUTPUT
 
    write_header "PCI Devices"
    ${LSPCI} -v >> $OUTPUT
 
    write_header "$IFCFG Output"
    $IFCFG >> $OUTPUT
 
    write_header "Kernel Routing Table"
    $ROUTE -n >> $OUTPUT
 
    write_header "DNS Client $DNSCLIENT Configuration"
     -f $DNSCLIENT ] && cat $DNSCLIENT >> $OUTPUT || echo "Error $DNSCLIENT file not found." >> $OUTPUT
 
    write_header "Network Configuration File"
    for f in $NETCFC
    do
        if  -f $f ]
        then
            echo "** $f **" >> $OUTPUT
            cat $f >> $OUTPUT
        else
            echo "Error $f not found." >> $OUTPUT
        fi
    done 
 
    write_header "IP4 Firewall Configuration"
    $IP4FW -L -n >> $OUTPUT
 
    write_header "IP6 Firewall Configuration"
    $IP6FW -L -n  >> $OUTPUT
 
    write_header "Network Stats"
    $NETSTAT -s >> $OUTPUT
 
    write_header "Network Tweaks via $SYSCTL"
     -f $SYSCTL ] && cat $SYSCTL >> $OUTPUT || echo "Error $SYSCTL not found." >>$OUTPUT
 
#
# Change Owner of Text File from root to User
#    
    chown $OWNER:users $OUTPUT

#
# Display Information about Using the Less command to view Text Fie
#

        echo
    echo "Your Network and PC Information Text File Has Been Created.  Your Text File will"
    echo "be loaded for viewing using the Less command..........Just Press Q to Quit Less."
    echo
        read -p "Please Press <enter> to continue..."

    less $OUTPUT

        echo
    echo "The Network Configuration Info was Written To the file: $OUTPUT."
    echo
}
 
chk_root
dump_info

exit 0
# End Of Script

Just as before, copy and paste the above text into a file called netinfo, saved in your area bin folder (~/bin/netinfo). To make the script file executable run the terminal command:

chmod +x ~/bin/netinfo

To use netinfo open a terminal session and just type the command netinfo with no run time options.

please_try_again, I can’t run the command lshw -class network, so lshw must not be installed by default. I would be happy to include any commed deemed good to include.
**
ken_yap
, should we remove the iptables or what do you suggest about running the script as root?
**
Akoellh
, I will check out the script you mention collectNWData Überblick / Overview | collectNWData.sh tonight when I have more time.

Thanks to everyone that has taken time to run the script and to provide feedback. I really appreciate your help and efforts!

Thank You,

Use sudo to run iptables and tell the user that the root password will be required at some point.

PS: netinfo runs the risk of being too generic a name. Apple’s older identity DB in OS/X was called netinfo and you might give people problems searching for it with engines. Something more unique perhaps, like jdmcdaniel3? :wink:

Originally Posted by brad455 View Post
NETCFC=“/etc/sysconfig/network/ifcfg-eth?”
I do not have this under this folder.

Well I have a network and it’s running, but this is what I found out about ifup

DESCRIPTION
The ifup and ifdown commands may be used to configure (or, respectively, deconfigure) network interfaces based on interface definitions in the file /etc/network/interfaces.

and this is what I found aobut ifconfig

DESCRIPTION
Ifconfig is used to configure the kernel-resident network interfaces.
It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.

If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.

Now I will say that my net card is eth1 because the one on the MB went out and I do have VBox installed which put a bridge (br0 and br1) on so that VBox could see the net.

But it sounds like ifup is just a way to bring your network up and down as to where ifconfig sets your network up at boot time.

Maybe you shouldn’t use documentation for Debian/*Buntu as a reference.

:slight_smile:

No, it is not. But it displays infos about wired and not wired network adapters (unlike lspci). Actually, hwinfo --network_ctrl does that too and provides a lot more informations than lspci (which might not really be needed here).

I agree with ken_yap that netinfo is a too generic name.

Well from what I have read it is not the (preferred method) it’s the (traditional method).

From the horses mouth openSUSE Reference pdf openSUSE 11.2.

In the Network Setup Method choose the way network connections are managed. If you want a NetworkManager desktop applet to manage connections for all interfaces, choose User Controlled with NetworkManager. This option is well suited for switching between multiple wired and wireless networks. If you do not run a desktop environment (GNOME or KDE), or if your computer is a Xen server, virtual system, or provides network services such as DHCP or DNS in your network, use the Traditional Method with ifup. If NetworkManager is used, nm-applet should be used to configure network options and the Overview, Hostname/DNS and Routing tabs of the Network Settings module are disabled. For more information on NetworkManager, see Chapter 5, Using Network-Manager (↑Start-Up).

When NetworkManager is enabled, netconfig (in policy mode auto) uses only NetworkManager settings, ignoring settings from any other interfaces configured using the traditional ifup method. If NetworkManager does not provide any setting, static settings are used as a fallback. A mixed usage of NetworkManager and the traditional ifup method is not supported.

I really don’t care which version a person likes Debian, Ubuntu, or openSUSE or any of the others all Linux versions should have the same basic commands for the base system. But I will say I do like a person that uses Linux because they have a open mind. I know that some commands are the same just by reading some of the Web sites and reading books. But Linux should be Linux. Now yes different distro’s will have their packages that they want in their disto’s to make them more attractive to the user’s, may be easier to use (Hmmm which one is that), more options at controlling the programs and harware or having better security.

That’s right. Let’s say I’m a traditionalist then. :wink:

[QUOTE=jdmcdaniel3;2237384][/QUOTE]

The script work very well for me after the changes. Great job. :slight_smile:

I guess you are LOL

That netinfo script inspired me that little one which checks if your internet ip (or another one given as argument) is currently blacklisted. No need to be root but you need to have either links or lynx installed.


#! /bin/bash

# Text browser, either links or lynx
TBrowser=links
# Preferred web browser
GBrowser=firefox
# read you Internet IP fron this site 
TestSite=http://ipinfo.info/html/my_ip_address.php
# Check if the IP is blacklisted by the honeypot project
honeypot=http://www.projecthoneypot.org/ip

ip=${1:-$($TBrowser -dump $TestSite | sed -n 's|^0-9]*\([1-9][0-9.]*\).*|\1|p')}

$TBrowser -dump  ${honeypot}_$ip | grep -q "We don't have data on this IP currently" && exec echo "Ip $ip is not blacklisted"
read -p "Ip $ip is currently blacklisted. See more info in webbrowser? [y|n]" YesNo
echo

 "$YesNo" == "y" -o "$YesNo" == "Y" ] && exec $GBrowser ${honeypot}_$ip