dotfiles/config/lemonbar/net.py
2018-09-05 09:07:37 +02:00

30 lines
738 B
Python
Executable file

#!/usr/bin/env python3
import psutil
import subprocess
netStats = psutil.net_if_stats()
netAddrs = psutil.net_if_addrs()
netIO = psutil.net_io_counters(pernic=True)
for iface in netStats.keys():
if not netStats[iface].isup or iface.startswith('lo'):
continue
ssid = ''
if iface.startswith('eth') or iface.startswith('enp'):
icon = 'E'
elif iface.startswith('wlan') or iface.startswith('wlp'):
icon = 'W'
cmd = ["iwgetid", iface, "--raw"]
p = subprocess.run(cmd, stdout=subprocess.PIPE)
ssid = p.stdout.strip().decode()
# TODO Real icons
# TODO USB tethering
# TODO tan / tun
else:
icon = '?'
print(icon, iface, ssid)
print(netIO[iface])