I cannot read the ipv6 address using netsh

33 Views Asked by At

I want to create a script where remove all the address I set manually in ethernet adaptor. To do that first I want to read the ip addresses. At the begging works perfectly but after I tried to remove them now even the read function is not working. Even after I made a restart I still receive the same error:

a = subprocess.getoutput(f'netsh interface ipv6 show address LocalNetwork')

Receive:

ERROR:cache_util_win.cc(20)] Unable to move the cache: Access is denied. (0x5)
ERROR:disk_cache.cc(205)] Unable to create cache
1

There are 1 best solutions below

0
Muhammad ibrahim On

The issue is with the permissions or envirnoment.

Try is with error handling:

import subprocess

try:
    command = 'netsh interface ipv6 show address LocalNetwork'
    output = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
    print(output.decode())
except subprocess.CalledProcessError as e:
    print(f"Command '{e.cmd}' returned non-zero exit status {e.returncode}.")
    print(f"Error message: {e.output.decode()}")
except Exception as e:
    print(f"An unexpected error occurred: {str(e)}")

It is using subprocess.check_output instead of getoutput for better error handling.