@@ -208,6 +208,8 @@ def _IsAddressBindable( addr ):
208208 except OSError :
209209 return False
210210
211+ _WINDOWS_LOOPBACK_IFACE = 'Loopback Pseudo-Interface 1'
212+
211213def _AddLoopbackAddr ( addr ):
212214 is_ipv6 = ':' in addr
213215 sys_name = platform .system ()
@@ -223,7 +225,12 @@ def _AddLoopbackAddr( addr ):
223225 print ( "Running 'ip -6 addr add %s/112 dev lo'" % addr )
224226 subprocess .run ( [ 'ip' , '-6' , 'addr' , 'add' , addr + '/112' , 'dev' , 'lo' ], check = True )
225227 # IPv4 on Linux: the entire 127/8 block is routable on lo, nothing to do.
226- # Windows: TBD when needed
228+ elif sys_name == 'Windows' :
229+ if is_ipv6 :
230+ print ( "Running 'netsh interface ipv6 add address \" %s\" %s'" % ( _WINDOWS_LOOPBACK_IFACE , addr ) )
231+ subprocess .run ( [ 'netsh' , 'interface' , 'ipv6' , 'add' , 'address' ,
232+ _WINDOWS_LOOPBACK_IFACE , addr ], check = True )
233+ # IPv4 on Windows: the entire 127/8 block is routable on the loopback adapter, nothing to do.
227234
228235def _RemoveLoopbackAddr ( addr ):
229236 is_ipv6 = ':' in addr
@@ -240,7 +247,12 @@ def _RemoveLoopbackAddr( addr ):
240247 print ( "Running 'ip -6 addr del %s/112 dev lo'" % addr )
241248 subprocess .run ( [ 'ip' , '-6' , 'addr' , 'del' , addr + '/112' , 'dev' , 'lo' ], check = False )
242249 # IPv4 on Linux: nothing was added, nothing to remove.
243- # Windows: TBD when needed
250+ elif sys_name == 'Windows' :
251+ if is_ipv6 :
252+ print ( "Running 'netsh interface ipv6 delete address \" %s\" %s'" % ( _WINDOWS_LOOPBACK_IFACE , addr ) )
253+ subprocess .run ( [ 'netsh' , 'interface' , 'ipv6' , 'delete' , 'address' ,
254+ _WINDOWS_LOOPBACK_IFACE , addr ], check = False )
255+ # IPv4 on Windows: nothing was added, nothing to remove.
244256
245257def SetupMockIPs ():
246258 """Add loopback aliases for every mock address that is not already bindable."""
@@ -264,7 +276,10 @@ def CheckMockIPsBindable():
264276 print ( "ERROR: the following addresses required by the mock network are not bindable:" )
265277 for addr in missing :
266278 print ( " " + addr )
267- print ( "Run 'sudo %s --setup-mock-ips' to add the required loopback aliases." % sys .argv [0 ] )
279+ if platform .system () == 'Windows' :
280+ print ( "Run '%s --setup-mock-ips' from an elevated (Administrator) prompt." % sys .argv [0 ] )
281+ else :
282+ print ( "Run 'sudo %s --setup-mock-ips' to add the required loopback aliases." % sys .argv [0 ] )
268283 sys .exit (1 )
269284
270285def _nat ( internal , gateway , nat_type ):
0 commit comments