Debian Codegraph @

ansible_collections/community/dns/plugins/module_utils/_ips.py

raw
1 # Copyright (c) 2023, Felix Fontein <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
6 # Do not use this from other collections or standalone plugins/modules!
7
8 from __future__ import annotations
9
10 import ipaddress
11
12 from ansible.module_utils.common.text.converters import to_text
13
14
15 def is_ip_address(server: str | bytes) -> bool:
16 try:
17 ipaddress.ip_address(to_text(server))
18 return True
19 except ValueError:
20 return False