utility.py (845B)
1import psutil
2from urllib.parse import urlparse
3import os
45
def getpath():
6'''get path of current directory'''
7return os.path.dirname(os.path.abspath(__file__))
89
def printUI():
10print('\nThis is telnet implementation.\n'
11'You can execute commands remotely.\n')
12print("\n")
1314
# get a list of all commands available on the system
15def getCommands():
16'''get a list of all commands available on the system'''
17return os.popen("help").read().split("\n")
1819
'''server functions'''
20# returns ip address assigned by router
21def get_ip_address():
22addrs = psutil.net_if_addrs()
23if "Wi-Fi" in addrs:
24wifi_info = addrs["Wi-Fi"]
25for info in wifi_info:
26if info.family == 2: # 2 is the address family for IPv4
27return info.address
28return None