Get the default localhost address. Defaults to IPv4 '127.0.0.1', but falls back to IPv6 '::1' if IPv4 is unavailable.
()
| 34 | return False |
| 35 | |
| 36 | def get_default_localhost(): |
| 37 | """Get the default localhost address. |
| 38 | Defaults to IPv4 '127.0.0.1', but falls back to IPv6 '::1' if IPv4 is unavailable. |
| 39 | """ |
| 40 | # First try IPv4 (preferred default) |
| 41 | if can_bind_ipv4_localhost(): |
| 42 | return "127.0.0.1" |
| 43 | |
| 44 | # Fall back to IPv6 if IPv4 is not available |
| 45 | if can_bind_ipv6_localhost(): |
| 46 | return "::1" |
| 47 | |
| 48 | # If neither works, still return IPv4 as a last resort |
| 49 | # (this is a very unusual situation) |
| 50 | return "127.0.0.1" |
| 51 | |
| 52 | def get_address(sock): |
| 53 | """Gets the socket address host and port.""" |
no test coverage detected
searching dependent graphs…