hotfix for mac-detection and various variable names (#139)
* Change Client-Name: The client name inside LVA is not capable of having spaces in the name. Fixed the example. * Add first version of Docker-Compose for developers * Add variable for network-interface and auto detection by default * Added autodetection for the MAC-Address based on the detected or specified network-interface. * Switched from listening on all IP-Addresses to the IP of the default interface, usually u set the correct network-interface and it will automatically detect the right IP-Address. * Added missing variables, fixed variables names * Fixed not working variables for example sound-files. * Moved the auto-name creation from shell to python. The name is no longer mandatory, it will be generated if no name is given.
This commit is contained in:
1 parent
f72e5c8d30
commit
4052daae01
11 files changed
+256
-113
No files matched your search
@@ -1,16 +1,44 @@
|
||||
"""Utility methods."""
|
||||
|
||||
import uuid
|
||||
# netifaces lib is from netifaces2
|
||||
import netifaces
|
||||
from collections.abc import Callable
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def get_mac() -> str:
|
||||
mac = uuid.getnode()
|
||||
mac_str = ":".join(f"{(mac >> i) & 0xff:02x}" for i in range(40, -1, -8))
|
||||
return mac_str
|
||||
|
||||
|
||||
def call_all(*callables: Optional[Callable[[], None]]) -> None:
|
||||
for item in filter(None, callables):
|
||||
item()
|
||||
|
||||
|
||||
def get_default_interface():
|
||||
"""Return the default network interface name, or None if not found."""
|
||||
default_gateway = netifaces.default_gateway()
|
||||
|
||||
if not default_gateway:
|
||||
print("No default gateway found")
|
||||
return None
|
||||
|
||||
# default_gateway is e.g. {InterfaceType.AF_INET: ('192.168.33.1', 'wlp0s20f3')}
|
||||
gateway_info = default_gateway.get(netifaces.AF_INET)
|
||||
if not gateway_info:
|
||||
print("No default IPv4 gateway found")
|
||||
return None
|
||||
|
||||
# gateway_info is a tuple: (gateway_ip, interface_name)
|
||||
interface_name = gateway_info[1]
|
||||
#print(f"Default interface: {interface_name}")
|
||||
return interface_name
|
||||
|
||||
|
||||
def get_default_ipv4(interface: str):
|
||||
if not interface:
|
||||
return None
|
||||
|
||||
addresses = netifaces.ifaddresses(interface)
|
||||
ipv4_info = addresses.get(netifaces.AF_INET)
|
||||
|
||||
if not ipv4_info:
|
||||
return None
|
||||
|
||||
return ipv4_info[0]["addr"]
|
||||
Reference in new issue
Block a user