#!/bin/bash
# A menu for my commonly-used network tools
IOFile=$(mktemp)
runprefix="$TERMINAL -o $IOFile -e"
MenuChoices="cisco\nconnect to\ndig\ngen pw\nkillvpn\nnmtui\nnmgui\nclonesite\nping\npingsubnet\nsmtp\nssh keys\nssl query\nspeedof lan\nspeedof wifi\nspeedof wan\ntrace route\nnewnet\nvm\nvnc\nwhois\nwinbox\nwireshark"
Say() { echo "$1" "$2" ; notify-send "$1" "$2" ;}
GetKeyFile() { KeyFile="$(find /home/$USER/.ssh -type f | dwmenu "Locate key file to use:")" || exit 1 ;}
GetHostName() { ServerHost=$(inprompt "$1") || exit 1 ;}
Menu2() {
choice=$(echo -e "$1" | dwmenu "$2") || exit
case $choice in
# Cisco choices
"asdm") $(ifinstalled javaws) && Util ASDM "Host:" ;;
"sho run") ciscorun ;;
"sho inv") ciscover ;;
# Connect To choices
FTP) Util FTP "Host:" ;;
RDP) connectcomputer RDP ;;
SMB) CIFS Mount ;;
SSH) connectcomputer SSH ;;
"Network Checkin") checkin ;;
# SMTP choices
default) $(ifinstalled msmtp) && msg ;;
telnet) Util SMTPTelnet "Mail Server:" ;;
config) openfile ~/.config/msmtp/config ;;
# SSH choices
"keygen") $runprefix ssh-keygen -t rsa ;;
"push key") Util PushKey "Remote Server Hostname:" ;;
"keychain") GetKeyFile
$runprefix ssh-add -k $KeyFile
if [[ $(grep "Identity added" $IOFile) ]]
then Say "👍 Private key added to keychain."
else Say "⛔ There was a problem adding key to keychain."
fi ;;
esac ;}
Util() {
GetHostName "$2"
case $1 in
ASDM) javaws https://$ServerHost/admin/public/asdm.jnlp ;;
Dig) TypeChoice=$(echo -e "any\nreverse\na\nmx\nns\nsrv\ntxt" | dwmenu "Record type:")
[[ $TypeChoice = "reverse" ]] && TypeChoice="x"
dig $TypeChoice $ServerHost >$IOFile
xdg-open $IOFile &disown ;;
FTP) $runprefix ftp $ServerHost ;;
Ping) $runprefix cping $ServerHost ;;
Whois) Say "⌛ Looking up whois for '$ServerHost'"
whois $ServerHost > $IOFile &&
xdg-open $IOFile ||
Say "⛔ There was a whois problem" ;;
TraceRoute) Say "⌛ Tracing route to '$ServerHost'"
traceroute $ServerHost > $IOFile &&
xdg-open $IOFile ||
Say "⛔ There was a route problem" ;;
CloneSite) Say "⌛ Attempting to download $ServerHost"
cd ~/Downloads
wget -mkEpnp $ServerHost &> $IOFile
if [[ $(grep "FINISHED" $IOFile) ]]
then Say "👍 $ServerHost download complete. $(grep 'Total wall clock time' $IOFile)"
else Say "⛔ There was a problem downloading $ServerHost"
fi ;;
SSLQuery) Say "⌛ Looking up SSL info for '$ServerHost'"
openssl s_client -showcerts -servername $ServerHost -connect $ServerHost:443 2>/dev/null | \
openssl x509 -inform pem -noout -text > $IOFile
xdg-open $IOFile &disown ;;
PushKey) GetKeyFile
$runprefix ssh-copy-id -i $KeyFile $ServerHost
if [[ $(grep "key(s) added: 1" $IOFile) ]]
then Say "👍 Key added. Try logging into $ServerHost."
else Say "⛔ There was a problem pushing key to $ServerHost."
fi ;;
SMTPTelnet) Sender=$(inprompt "Sender e-mail:") || exit
Recipient=$(inprompt "Recipient e-mail:") || exit
Subject=$(inprompt "Subject:") || exit
Body=$(inprompt "Message Body:") || exit
$runprefix expect ~/.local/bin/expect/smtptelnet "$ServerHost" "$Sender" "$Recipient" "$Subject" "$Body"
if [[ $(grep "Queued mail for deliver" /tmp/smtp-telnet) ]]
then Say "👍 SMTP successful."
else Say "⛔ SMTP was not successful."
fi ;;
esac ;}
CIFS() {
case $1 in
Ask) case $(echo -e "Yes\nNo" | dwmenu "Add another?") in
"Yes") CIFS Wiz ;;
"No") CIFS Finish ;;
esac ;;
Finish) sudo cp /tmp/fstab-modified /etc/fstab
sudo mount -a
exit ;;
Mount) cat /etc/fstab >/tmp/fstab-original
cat /etc/fstab >/tmp/fstab-modified
SpaceChar='\\040'
CIFS Wiz ;;
Wiz) LocalPath=$(inprompt "Local path for this mount:") || exit
ConnectTo=$(inprompt "Network server name or IP:") || exit
ConnectUsr=$(inprompt "Username to connect with:") || exit
ConnectPw=$(dmenupass "Password to connect with:") || exit
ShareName=$(inprompt "Name of the remote share:") || exit
ConnectPw=$(echo $ConnectPw | sed -e 's/ /'$SpaceChar'/g')
FSTABEDIT="//$ConnectTo/$ShareName $LocalPath cifs username=$ConnectUsr,password=$ConnectPw,uid=$(id -u $USER),gid=$(id -g $USER),iocharset=utf8,vers=1.0 0 0"
sudo mkdir -p $LocalPath
echo $FSTABEDIT >> /tmp/fstab-modified
CIFS Ask ;;
esac ;}
case $(echo -e "Clients\nCommands" | dwmenu "🔗 Network Command") in
Clients) nets ;;
Commands) case $(echo -e "$MenuChoices" | sort -n | dwmenu "🔗 Network Command") in
"gen pw") $runprefix genpw ;;
"killvpn") killvpn ;;
"nmtui") $runprefix nmtui ;;
"nmgui") nm-connection-editor ;;
"newnet") sudo systemctl restart NetworkManager ;;
"speedof lan") $runprefix speedof -l ;;
"speedof wifi") $runprefix speedof -w ;;
"speedof wan") speedof -i ;;
"cisco") Menu2 "asdm\nsho run\nsho inv" "Cisco Options:" ;;
"connect to") Menu2 "FTP\nRDP\nSMB\nSSH\nNetwork Checkin" "Connection Options:" ;;
"smtp") Menu2 "default\ntelnet\nconfig" "SMTP Options:" ;;
"ssh keys") Menu2 "keygen\npush key\nkeychain" "SSH Key Options:" ;;
"clonesite") Util CloneSite "Website URL to clone:" ;;
"ping") Util Ping "Hostname or IP:" ;;
"ssl query") Util SSLQuery "Domain Name:" ;;
"pingsubnet") $(ifinstalled nmap) && $runprefix pingsubnet $(inprompt "Subnet to ping:") ;;
"trace route") $(ifinstalled traceroute) && Util TraceRoute "Hostname or IP:" ;;
"dig") $(ifinstalled dig) && Util Dig "Domain Name:" ;;
"vm") $(ifinstalled virtualbox) &&
choices=$(VBoxManage list vms | awk '{print $1}' | sed -e 's/^"//' -e 's/"$//') &&
choice=$(echo -e "$choices" | dwmenu "Virtual Machines:") || exit
if [[ $(VBoxManage list runningvms | grep $choice) ]];
then Say "⛔ $choice is already running."
else Say "👍 Starting $choice." ; VBoxManage startvm "$choice"
fi ;;
"vnc") $(ifinstalled vncviewer) && vncviewer ;;
"whois") $(ifinstalled whois) && Util Whois "Domain Name:" ;;
"winbox") $(ifinstalled winbox) && winbox ;;
"wireshark") $(ifinstalled wireshark-gtk) && sudo wireshark-gtk ;;
esac ;;
esac