Skip to content

Commit

Permalink
Add Network Snapshot Script (#8)
Browse files Browse the repository at this point in the history
* Add network-snapshot.sh

A bash script to gather network stats from ip, netstat, arp, and
ethtool commands. Script will exist in root directory of image and
output is saved in /home/network-snapshot-output dir with a date based
on the day when the script was executed.

Signed-off-by: Mick Tarsel <[email protected]>

* Fix back slashes

---------

Signed-off-by: Mick Tarsel <[email protected]>
  • Loading branch information
mtarsel authored Mar 5, 2023
1 parent bcfcea0 commit 149024a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ RUN dnf install --best --refresh -y \
udev \
vim-enhanced \
&& dnf clean all \
&& rm -rf /var/cache/yum \
&& rm -rf /var/cache/yum

COPY --chmod=777 network-snapshot.sh /usr/local/bin/network-snapshot.sh

CMD ["sleep", "infinity"]
77 changes: 77 additions & 0 deletions network-snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

#Written by Mick Tarsel
#create a network "snapshot"
#Only shows IPv4

OUT_DIR="/home/network-snapshot-output"
OUT_FILE=$OUT_DIR/$(date +"%m-%d-%Y")-outputski.txt

title () {
echo "" &>> $OUT_FILE;
echo "" &>> $OUT_FILE;
echo "" &>> $OUT_FILE;
echo "#####################" &>> $OUT_FILE;
echo " $1 " &>> $OUT_FILE;
echo "#####################" &>> $OUT_FILE;
echo "" &>> $OUT_FILE;
}

command_out () {
#the first parameter of this func is the command. save output to file
$1 &>> $OUT_FILE
}

mkdir -p $OUT_DIR
touch $OUT_FILE

primary_interface=$(ip -o -4 route show to default | awk '{print $5}')
#list default route and assume that device is primary interface
hostname=$(cat /etc/hostname)

title "Hostname: $hostname"

title "Default Route Network Interface: $primary_interface"

title "IPv4 Addresses"
command_out "ip -4 addr"

title "IP Link Stats"
command_out "ip -4 -s link show"

title "Netstat Stats"
command_out "netstat -4 -s"

title "Netstat Listening Ports"
command_out "netstat -tulpn | grep LISTEN"

title "ARP"
command_out "arp"

title "Route"
command_out "route -n"

title "IP Route"
command_out "ip -4 route"

title "IP Neighbor"
command_out "ip -4 neigh show"

title "All IP Addresses"
command_out "ip addr"

title "ethtool info for $primary_interface"
command_out "ethtool -i $primary_interface"

title "ethtool Stats for $primary_interface"
command_out "ethtool -S $primary_interface"

title "ethtool Features for $primary_interface"
command_out "ethtool -k $primary_interface"

echo "Network info saved in $OUT_FILE"

#Some other helpful places to check :)
#cat /proc/sys/net/ipv4/conf
#iptables-save -c
#journalctl -u Network-Manager.service --no-pager

0 comments on commit 149024a

Please sign in to comment.