#!/bin/bash
# twily-scrpt
# dependencies~
# speedometer, tshark, tcptrack, iftop, traceroute, nethogs, netstat, ssh, dd, sudo, +(iperf, nc/netcat)
opt=$1
add=$2 # port or ip
default_dev="wlp0s20f3"
default_ip=127.0.0.1
default_port=8000
case "$opt" in
"2") # list port listeners
sudo netstat -plnt
;;
"3") # nethog list processes
if [ -z "$add" ]; then add=$default_dev; fi
sudo nethogs -v 3 -a -C $add
;;
"4") # trace connection
if [ -z "$add" ]; then add=$default_ip; fi
traceroute $add
;;
"5") # speedtest between 2 devices
if [ -z "$add" ]; then add=$default_ip; fi
ssh amalie@$add 'dd if=/dev/zero bs=1GB count=3 2>/dev/null' | dd of=/dev/null status=progress
# alt methods
# nc -vvlnp 12345 >/dev/null
# dd if=/dev/zero bs=1M count=1K | nc -vvn 10.10.0.2 12345
#--or
# iperf -sp 12345
# iperf -c <address of other computer> -p 12345
;;
"6") # general traffic overview
if [ -z "$add" ]; then add=$default_dev; fi
sudo iftop -i $add
;;
"7") # more general traffic overview
if [ -z "$add" ]; then add=$default_dev; fi
sudo tcptrack -fr 10 -i $add
;;
"8") # capture packets
if [ -z "$add" ]; then add=$default_port; fi
sudo tshark -i lo -n -s0 -f "port $add"
;;
*) # (default 1 / empty) bandwidth monitoring
if [ -z "$add" ]; then add=$default_dev; fi
sudo speedometer -l -r $add -t $add -c -r lo -t lo -m $(( 1024 * 1024 * 3 / 2 ))
#sudo speedometer -l -r $add -t $add -c -r tun0 -t tun0 -c -r lo -t lo -m $(( 1024 * 1024 * 3 / 2 ))
#speedometer -l -r tun0 -t tun0 -m $(( 1024 * 1024 * 3 / 2 ))
#speedometer -l -r lo -t lo -m $(( 1024 * 1024 * 3 / 2 ))
;;
esac
Top