2021-09-24 14:10:04 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-04-01 11:18:18 -04:00
|
|
|
# MIT License
|
|
|
|
#
|
|
|
|
# Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
2021-09-24 14:10:04 -04:00
|
|
|
import RNS
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from RNS._version import __version__
|
|
|
|
|
|
|
|
def size_str(num, suffix='B'):
|
|
|
|
units = ['','K','M','G','T','P','E','Z']
|
|
|
|
last_unit = 'Y'
|
|
|
|
|
|
|
|
if suffix == 'b':
|
|
|
|
num *= 8
|
|
|
|
units = ['','K','M','G','T','P','E','Z']
|
|
|
|
last_unit = 'Y'
|
|
|
|
|
|
|
|
for unit in units:
|
|
|
|
if abs(num) < 1000.0:
|
|
|
|
if unit == "":
|
|
|
|
return "%.0f %s%s" % (num, unit, suffix)
|
|
|
|
else:
|
|
|
|
return "%.2f %s%s" % (num, unit, suffix)
|
|
|
|
num /= 1000.0
|
|
|
|
|
|
|
|
return "%.2f%s%s" % (num, last_unit, suffix)
|
|
|
|
|
|
|
|
def program_setup(configdir, dispall=False, verbosity = 0):
|
|
|
|
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
2022-04-18 10:41:38 -04:00
|
|
|
|
2022-04-20 03:59:58 -04:00
|
|
|
stats = None
|
2022-04-18 10:41:38 -04:00
|
|
|
try:
|
2022-04-20 03:59:58 -04:00
|
|
|
stats = reticulum.get_interface_stats()
|
2022-04-18 10:41:38 -04:00
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
2022-04-20 03:59:58 -04:00
|
|
|
if stats != None:
|
|
|
|
for ifstat in stats["interfaces"]:
|
2021-09-24 14:10:04 -04:00
|
|
|
name = ifstat["name"]
|
|
|
|
|
|
|
|
if dispall or not (name.startswith("LocalInterface[") or name.startswith("TCPInterface[Client")):
|
2021-10-08 12:30:17 -04:00
|
|
|
print("")
|
2022-04-20 03:59:58 -04:00
|
|
|
|
2021-09-24 14:10:04 -04:00
|
|
|
if ifstat["status"]:
|
|
|
|
ss = "Up"
|
|
|
|
else:
|
|
|
|
ss = "Down"
|
|
|
|
|
2022-04-16 17:26:57 -04:00
|
|
|
if ifstat["mode"] == RNS.Interfaces.Interface.Interface.MODE_ACCESS_POINT:
|
|
|
|
modestr = "Access Point"
|
|
|
|
elif ifstat["mode"] == RNS.Interfaces.Interface.Interface.MODE_POINT_TO_POINT:
|
|
|
|
modestr = "Point-to-Point"
|
|
|
|
else:
|
|
|
|
modestr = "Full"
|
|
|
|
|
|
|
|
|
2021-09-24 14:10:04 -04:00
|
|
|
if ifstat["clients"] != None:
|
|
|
|
clients = ifstat["clients"]
|
|
|
|
if name.startswith("Shared Instance["):
|
2022-04-16 17:26:57 -04:00
|
|
|
cnum = max(clients-1,0)
|
|
|
|
if cnum == 1:
|
|
|
|
spec_str = " program"
|
|
|
|
else:
|
|
|
|
spec_str = " programs"
|
|
|
|
|
|
|
|
clients_string = "Serving : "+str(cnum)+spec_str
|
2021-09-24 14:10:04 -04:00
|
|
|
else:
|
2022-04-16 17:26:57 -04:00
|
|
|
clients_string = "Clients : "+str(clients)
|
2021-09-24 14:10:04 -04:00
|
|
|
|
|
|
|
else:
|
|
|
|
clients = None
|
|
|
|
|
|
|
|
print(" {n}".format(n=ifstat["name"]))
|
2022-04-16 17:26:57 -04:00
|
|
|
print(" Status : {ss}".format(ss=ss))
|
2022-04-17 13:07:32 -04:00
|
|
|
|
2022-04-16 17:26:57 -04:00
|
|
|
if clients != None:
|
|
|
|
print(" "+clients_string)
|
|
|
|
|
2022-04-17 11:30:39 -04:00
|
|
|
if not (name.startswith("Shared Instance[") or name.startswith("TCPInterface[Client") or name.startswith("LocalInterface[")):
|
2022-04-16 17:26:57 -04:00
|
|
|
print(" Mode : {mode}".format(mode=modestr))
|
2022-02-26 15:04:54 -05:00
|
|
|
|
2022-04-17 13:07:32 -04:00
|
|
|
if "bitrate" in ifstat and ifstat["bitrate"] != None:
|
|
|
|
print(" Rate : {ss}".format(ss=speed_str(ifstat["bitrate"])))
|
|
|
|
|
|
|
|
if "peers" in ifstat and ifstat["peers"] != None:
|
|
|
|
print(" Peers : {np} reachable".format(np=ifstat["peers"]))
|
|
|
|
|
2022-04-17 13:35:05 -04:00
|
|
|
if "i2p_b32" in ifstat and ifstat["i2p_b32"] != None:
|
2022-04-16 17:26:57 -04:00
|
|
|
print(" I2P B32 : {ep}".format(ep=str(ifstat["i2p_b32"])))
|
2022-02-26 15:04:54 -05:00
|
|
|
|
2022-04-18 10:41:38 -04:00
|
|
|
if "announce_queue" in ifstat and ifstat["announce_queue"] != None and ifstat["announce_queue"] > 0:
|
|
|
|
aqn = ifstat["announce_queue"]
|
|
|
|
if aqn == 1:
|
|
|
|
print(" Queued : {np} announce".format(np=aqn))
|
|
|
|
else:
|
|
|
|
print(" Queued : {np} announces".format(np=aqn))
|
|
|
|
|
2022-04-17 13:08:48 -04:00
|
|
|
print(" Traffic : {txb}↑\n {rxb}↓".format(rxb=size_str(ifstat["rxb"]), txb=size_str(ifstat["txb"])))
|
2021-09-25 17:56:56 -04:00
|
|
|
|
2022-04-20 03:59:58 -04:00
|
|
|
if "transport_id" in stats and stats["transport_id"] != None:
|
|
|
|
print("\n Transport Instance "+RNS.prettyhexrep(stats["transport_id"])+" running")
|
|
|
|
|
2021-09-25 17:56:56 -04:00
|
|
|
print("")
|
2021-09-25 05:27:43 -04:00
|
|
|
|
2021-09-24 14:10:04 -04:00
|
|
|
else:
|
|
|
|
print("Could not get RNS status")
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
parser = argparse.ArgumentParser(description="Reticulum Network Stack Status")
|
|
|
|
parser.add_argument("--config", action="store", default=None, help="path to alternative Reticulum config directory", type=str)
|
|
|
|
parser.add_argument("--version", action="version", version="rnstatus {version}".format(version=__version__))
|
|
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
"-a",
|
|
|
|
"--all",
|
|
|
|
action="store_true",
|
|
|
|
help="show all interfaces",
|
|
|
|
default=False
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument('-v', '--verbose', action='count', default=0)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.config:
|
|
|
|
configarg = args.config
|
|
|
|
else:
|
|
|
|
configarg = None
|
|
|
|
|
|
|
|
program_setup(configdir = configarg, dispall = args.all, verbosity=args.verbose)
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("")
|
|
|
|
exit()
|
|
|
|
|
2022-04-17 13:07:32 -04:00
|
|
|
def speed_str(num, suffix='bps'):
|
|
|
|
units = ['','k','M','G','T','P','E','Z']
|
|
|
|
last_unit = 'Y'
|
|
|
|
|
|
|
|
if suffix == 'Bps':
|
|
|
|
num /= 8
|
|
|
|
units = ['','K','M','G','T','P','E','Z']
|
|
|
|
last_unit = 'Y'
|
|
|
|
|
|
|
|
for unit in units:
|
|
|
|
if abs(num) < 1000.0:
|
|
|
|
return "%3.2f %s%s" % (num, unit, suffix)
|
|
|
|
num /= 1000.0
|
|
|
|
|
|
|
|
return "%.2f %s%s" % (num, last_unit, suffix)
|
|
|
|
|
2021-09-24 14:10:04 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|