View Single Post
  #8   (View Single Post)  
Old 16th April 2019
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,253
Default

Tint2 executor to display current wifi connection data.

This project tries to use OpenBSD tools whenever possible and recently the project has implemented a feature which can connect to multiple networks provided they are listed in your /etc/hostname.if file. The following script lets the user know, with a single click, which of the possible networks is being used.

OpenBSD gains Wi-Fi "auto-join".

The script is still a little rough. One issue is that ifconfig line that is parsed for connection data can lead off with "nwid" or "ieee80211". The script currently uses "grep ieee80211". If you do not use the join command your can either replace ieee80211 with nwid in the script or add "join" to your /etc/hostname.if. Some spacing issues in the yad output lead to the addition of non-printable \t "tab".
obsd_wifi_tint2.sh
Code:
#!/bin/sh
# STDERR (descriptor 2) text to STDOUT (descriptor 1)
TEST="$(nc -dzw1 8.8.8.8 443 2>&1)"
if echo $TEST | grep '^Connect' >/dev/null ; then

# IFS; Inter Field Separator (see man ksh)
# to preserve newlines,save and set IFS to space only   
OLD_IFS="${IFS}"
IFS=" "

# capture 'ifconfig' output once and reuse ....
IFCONFIG=$(ifconfig)

NWID="$(echo ${IFCONFIG} | awk '/nwid/{print $3}')" 
CHAN="$(echo ${IFCONFIG} | awk '/nwid/{print $5}')"
BSSID="$(echo ${IFCONFIG} | awk '/nwid/{print $7}')"
SN="$(echo ${IFCONFIG} | awk '/nwid/{print $8}')"
IP="$(echo ${IFCONFIG} | awk '/inet/{print $2}' | tail -n1)"

cat <<END
--------------------------------------------------------------
\tCurrent WiFi Connection
--------------------------------------------------------------

\tNWID  :  $NWID
\tCHAN  :  $CHAN
\tBSSID :  $BSSID
\tS/N\t :  $SN
\tIP\t  :  $IP
END
else
cat <<END
--------------------------------------------------------------
\tCurrently No Connection
\tto google.com port 443
--------------------------------------------------------------
END
fi
yad_wifi.sh
Code:
#!/bin/sh
yad --geometry=-0+38 --text="$(sh /home/jsh/scripts/obsd_wifi_tint2.sh 2>&1)" \
--undecorated --button=gtk-close:6
I added this as a second "button" in my tint2 panel configuration (P).
Code:
#-------------------------------------
# Panel
panel_items = TSPPC
panel_size = 100% 38
-----
 #-------------------------------------
# Button 1
button = new
button_icon = /usr/local/share/icons/Adwaita/32x32/status/weather-overcast.png
button_tooltip = "Yakima, WA Weather"
button_padding = 6 3 0
button_max_icon_size = 24
button_lclick_command = sh ~/scripts/yad_weather.sh
button_mclick_command =
button_rclick_command = sh ~/scripts/yad_weather.sh
# Button 2
button = new
button_icon = /usr/local/share/icons/Adwaita/32x32/devices/network-wireless.png
button_tooltip = "Wireless Connection"
button_padding = 6 3 0
button_max_icon_size = 24
button_lclick_command = sh ~/scripts/yad_wifi.sh
button_mclick_command =
button_rclick_command = sh ~/scripts/yad_wifi.sh
For those using Gnome, KDE4 or XFCE4, you can either make a obsd_wifi.desktop file ,described above, or use yad --notification to produce a sytemtray entry
yad Notification Options
yad Notification

This is the output positioned under the wireless icon in the tint2 panel
Name:  wifi.jpg
Views: 466
Size:  18.1 KB

Last edited by shep; 8th June 2019 at 06:41 PM. Reason: Incorportated @Head_on_a_Stick suggestions
Reply With Quote