[fix] config_ssh, connect_server, network
[dotfiles_afify.git] / .scripts / network
blob84b850eddc21a1ce8c001b338e3c3a51104c26d6
1 #!/usr/bin/env bash
3 wifi_icon="直"
4 eth_icon=""
5 other_icon="禍"
6 bpm=1048576 # 1024*1024
7 up_interfaces=$(ifconfig | grep "UP,BROADCAST,RUNNING" |\
8 sed 's/://' | awk '{print $1}')
9 up_type=
10 ssid_strength=
12 check_type(){
13 case $(uname) in
14 Linux) case $1 in
15 wlp*) up_type=wlan ;;
16 enp*) up_type=eth ;;
17 *) up_type=other ;;
18 esac ;;
19 OpenBSD) up_type=$(ifconfig $1 | grep "groups" | awk '{print $2}') ;;
20 esac
23 get_ssid_strength(){
24 if [[ "$up_type" == "wlan" ]]; then
25 case $(uname) in
26 Linux)
27 wifi_ssid=$(iw dev $1 link | grep SSID | cut -d " " -f 2-)
28 wifi_strength=$(grep "^\s*w" /proc/net/wireless |\
29 awk '{print int($3 * 100 / 70) "%"}')
30 ssid_strength='\n'$wifi_ssid' '$wifi_strength;;
32 OpenBSD) ssid_strength=$(echo "$int" | grep join |\
33 awk '{print "\n"$3"\t"int((-0.0154*$8*$8)-(0.3794*$8)+98.182)"%"}');;
34 esac
35 else
36 ssid_strength=
41 print_status(){
42 for each_interface in $up_interfaces; do
43 # case $(uname) in
44 # Linux) total_in=$(
45 # cat /sys/class/net/$each_interface/statistics/rx_bytes);;
46 # OpenBSD) total_in=$(netstat -b -I $each_interface |\
47 # egrep "[a-z0-9]{2}:" | awk '{print $5}');;
48 # esac
49 check_type $each_interface
50 case $up_type in
51 egress) icon=$other_icon ;;
52 wlan) icon=$wifi_icon ;;
53 eth) icon=$eth_icon ;;
54 *) icon=$other_icon ;;
55 esac
56 # in_sum=$(($total_in / $bpm))
57 # result+=$icon' '$in_sum' '
58 result+=$icon' '
59 done
60 echo $result
63 notify_status(){
64 for each_interface in $up_interfaces; do
65 int=$(ifconfig $each_interface)
66 ip=$(echo "$int" | grep 'inet ' | awk '{print $2}')
67 check_type $each_interface
68 get_ssid_strength $each_interface
69 result+="$up_type\t($each_interface)$ssid_strength\n$ip\n\n"
70 done
71 notify-send "Network details" "$result"
74 print_ips(){
75 ifconfig | grep -A1 "$up_interfaces" | grep 'inet' | awk '{print $2}'
78 case $1 in
79 notify) notify_status ;;
80 ips) print_ips ;;
81 *) print_status ;;
82 esac