(protocol_version)
| 250 | |
| 251 | |
| 252 | def _getNetworkAddrs(protocol_version): |
| 253 | addrs = [] |
| 254 | ifaces = ifaddr.get_adapters() |
| 255 | |
| 256 | # ifaddr library only returns IPv4 and IPv6 addresses |
| 257 | if protocol_version == socket.AF_INET: |
| 258 | for iface in ifaces: |
| 259 | for ip in iface.ips: |
| 260 | if isinstance(ip.ip, str): |
| 261 | ip_address = ipaddress.ip_address(ip.ip) |
| 262 | if not ip_address.is_loopback and not ip_address.is_link_local: |
| 263 | addrs.append(ip_address) |
| 264 | elif protocol_version == socket.AF_INET6: |
| 265 | for iface in ifaces: |
| 266 | for ip in iface.ips: |
| 267 | if isinstance(ip.ip, tuple): |
| 268 | ip_address = ipaddress.ip_address(f"{ip.ip[0]}%{ip.ip[2]}") |
| 269 | if not ip_address.is_loopback and not ip_address.is_link_local: |
| 270 | addrs.append(ip_address) |
| 271 | else: |
| 272 | logger.warning(f"requested protocol version ({protocol_version}) is not" |
| 273 | f" IPv4 ({socket.AF_INET}) or IPv6 ({socket.AF_INET6})") |
| 274 | |
| 275 | return addrs |
| 276 | |
| 277 | |
| 278 | def _generateInstanceId(): |
no outgoing calls
no test coverage detected