feat: dns support
This commit is contained in:
@ -29,8 +29,9 @@ from .utils import get_preferences, get_expanded_icon
|
|||||||
from replication.constants import RP_COMMON
|
from replication.constants import RP_COMMON
|
||||||
from replication.interface import session
|
from replication.interface import session
|
||||||
|
|
||||||
IP_EXPR = re.compile('\d+\.\d+\.\d+\.\d+')
|
# From https://stackoverflow.com/a/106223
|
||||||
|
IP_REGEX = re.compile("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$")
|
||||||
|
HOSTNAME_REGEX = re.compile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$")
|
||||||
|
|
||||||
def randomColor():
|
def randomColor():
|
||||||
"""Generate a random color """
|
"""Generate a random color """
|
||||||
@ -53,10 +54,13 @@ def update_panel_category(self, context):
|
|||||||
|
|
||||||
|
|
||||||
def update_ip(self, context):
|
def update_ip(self, context):
|
||||||
ip = IP_EXPR.search(self.ip)
|
ip = IP_REGEX.search(self.ip)
|
||||||
|
dns = HOSTNAME_REGEX.search(self.ip)
|
||||||
|
|
||||||
if ip:
|
if ip:
|
||||||
self['ip'] = ip.group()
|
self['ip'] = ip.group()
|
||||||
|
elif dns:
|
||||||
|
self['ip'] = dns.group()
|
||||||
else:
|
else:
|
||||||
logging.error("Wrong IP format")
|
logging.error("Wrong IP format")
|
||||||
self['ip'] = "127.0.0.1"
|
self['ip'] = "127.0.0.1"
|
||||||
|
Reference in New Issue
Block a user