| 272 | _WINDOWS_LOOPBACK_IFACE = 'Loopback Pseudo-Interface 1' |
| 273 | |
| 274 | def _AddLoopbackAddr( addr ): |
| 275 | is_ipv6 = ':' in addr |
| 276 | sys_name = platform.system() |
| 277 | if sys_name == 'Darwin': |
| 278 | if is_ipv6: |
| 279 | print( "Running 'ifconfig lo0 inet6 %s'" % addr ) |
| 280 | subprocess.run( [ 'ifconfig', 'lo0', 'inet6', addr ], check=True ) |
| 281 | else: |
| 282 | print( "Running 'ifconfig lo0 alias %s'" % addr ) |
| 283 | subprocess.run( [ 'ifconfig', 'lo0', 'alias', addr ], check=True ) |
| 284 | elif sys_name == 'Linux': |
| 285 | if is_ipv6: |
| 286 | print( "Running 'ip -6 addr add %s/112 dev lo'" % addr ) |
| 287 | subprocess.run( [ 'ip', '-6', 'addr', 'add', addr + '/112', 'dev', 'lo' ], check=True ) |
| 288 | # IPv4 on Linux: the entire 127/8 block is routable on lo, nothing to do. |
| 289 | elif sys_name == 'Windows': |
| 290 | if is_ipv6: |
| 291 | print( "Running 'netsh interface ipv6 add address \"%s\" %s'" % ( _WINDOWS_LOOPBACK_IFACE, addr ) ) |
| 292 | subprocess.run( [ 'netsh', 'interface', 'ipv6', 'add', 'address', |
| 293 | _WINDOWS_LOOPBACK_IFACE, addr ], check=True ) |
| 294 | # IPv4 on Windows: the entire 127/8 block is routable on the loopback adapter, nothing to do. |
| 295 | |
| 296 | def _RemoveLoopbackAddr( addr ): |
| 297 | is_ipv6 = ':' in addr |