mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-26 02:38:47 +02:00
Added support for pools in DHCP address #104
Added support for active addresses in DHCP
This commit is contained in:
parent
ab97fa60f7
commit
b1da24b9f4
1 changed files with 35 additions and 0 deletions
|
@ -3,6 +3,8 @@
|
||||||
import re
|
import re
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from ipaddress import ip_address, IPv4Network
|
from ipaddress import ip_address, IPv4Network
|
||||||
from mac_vendor_lookup import AsyncMacLookup
|
from mac_vendor_lookup import AsyncMacLookup
|
||||||
|
@ -58,6 +60,14 @@ from .mikrotikapi import MikrotikAPI
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_ip(address):
|
||||||
|
try:
|
||||||
|
ipaddress.ip_address(address)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# MikrotikControllerData
|
# MikrotikControllerData
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -1330,7 +1340,9 @@ class MikrotikControllerData:
|
||||||
key="mac-address",
|
key="mac-address",
|
||||||
vals=[
|
vals=[
|
||||||
{"name": "mac-address"},
|
{"name": "mac-address"},
|
||||||
|
{"name": "active-mac-address"},
|
||||||
{"name": "address", "default": "unknown"},
|
{"name": "address", "default": "unknown"},
|
||||||
|
{"name": "active-address", "default": "unknown"},
|
||||||
{"name": "host-name", "default": "unknown"},
|
{"name": "host-name", "default": "unknown"},
|
||||||
{"name": "status", "default": "unknown"},
|
{"name": "status", "default": "unknown"},
|
||||||
{"name": "last-seen", "default": "unknown"},
|
{"name": "last-seen", "default": "unknown"},
|
||||||
|
@ -1342,6 +1354,29 @@ class MikrotikControllerData:
|
||||||
|
|
||||||
dhcpserver_query = False
|
dhcpserver_query = False
|
||||||
for uid in self.data["dhcp"]:
|
for uid in self.data["dhcp"]:
|
||||||
|
# is_valid_ip
|
||||||
|
if self.data["dhcp"][uid]["address"] != "unknown":
|
||||||
|
if not is_valid_ip(self.data["dhcp"][uid]["address"]):
|
||||||
|
self.data["dhcp"][uid]["address"] = "unknown"
|
||||||
|
|
||||||
|
if (
|
||||||
|
self.data["dhcp"][uid]["active-address"]
|
||||||
|
!= self.data["dhcp"][uid]["address"]
|
||||||
|
and self.data["dhcp"][uid]["active-address"] != "unknown"
|
||||||
|
):
|
||||||
|
self.data["dhcp"][uid]["address"] = self.data["dhcp"][uid][
|
||||||
|
"active-address"
|
||||||
|
]
|
||||||
|
|
||||||
|
if (
|
||||||
|
self.data["dhcp"][uid]["mac-address"]
|
||||||
|
!= self.data["dhcp"][uid]["active-mac-address"]
|
||||||
|
and self.data["dhcp"][uid]["active-mac-address"] != "unknown"
|
||||||
|
):
|
||||||
|
self.data["dhcp"][uid]["mac-address"] = self.data["dhcp"][uid][
|
||||||
|
"active-mac-address"
|
||||||
|
]
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not dhcpserver_query
|
not dhcpserver_query
|
||||||
and self.data["dhcp"][uid]["server"] not in self.data["dhcp-server"]
|
and self.data["dhcp"][uid]["server"] not in self.data["dhcp-server"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue