Skip to content

Commit

Permalink
fix(resolving) support domain names that start with a number.
Browse files Browse the repository at this point in the history
Domains are allowed to start with numbers and are currently not resolved
because of the current simple regex.

The new regexes better cover the IPv4 and IPv6 address (with optional
netmask)
  • Loading branch information
pjbakker committed Mar 19, 2021
1 parent 11d3d79 commit 120a653
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions _states/ufw.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ def _changed(name, msg, **changes):


def _resolve(host):
# let's just see if it starts with a number or a colon, for simplicity
if re.match(r'^[0-9:]', host):
# pure IP address / netmask IPv4?
if re.match(r'^([0-9\.])+(/[0-9]+)?$', host):
return host

# pure IPv6 address / netmask?
if re.match(r'^([0-9a-f:]+)(/[0-9]+)?$', host):
return host

return socket.gethostbyname(host)
Expand Down

0 comments on commit 120a653

Please sign in to comment.