Autosuggestion for network interfaces ips
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from ipaddress import ip_interface
|
||||
import os, socket, secrets
|
||||
import os, socket, secrets, psutil
|
||||
|
||||
LOCALHOST_IP = socket.gethostbyname(os.getenv("LOCALHOST_IP","127.0.0.1"))
|
||||
|
||||
@@ -19,4 +19,12 @@ def ip_parse(ip:str):
|
||||
return str(ip_interface(ip).network)
|
||||
|
||||
def ip_family(ip:str):
|
||||
return "ip6" if ip_interface(ip).version == 6 else "ip"
|
||||
return "ip6" if ip_interface(ip).version == 6 else "ip"
|
||||
|
||||
def get_interfaces():
|
||||
def _get_interfaces():
|
||||
for int_name, interfs in psutil.net_if_addrs().items():
|
||||
for interf in interfs:
|
||||
if interf.family in [socket.AF_INET, socket.AF_INET6]:
|
||||
yield {"name": int_name, "addr":interf.address}
|
||||
return list(_get_interfaces())
|
||||
Reference in New Issue
Block a user