import os
import re
import ctypes
from subprocess import PIPE, Popen

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

def ecmd(command):
    
    with disable_file_system_redirection():
        obj = Popen(command, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = obj.communicate()
    ret=obj.returncode
    return ret,out,err

with disable_file_system_redirection():
    net=os.popen("netsh interface show interface").read()

net_output = net.strip().splitlines()[2:]
na = list(map(lambda x: x.split('  ')[-1], net_output))

for i in na:
    ret,out,err = ecmd(('netsh interface set interface "%s" disable'%(i)))
    if ret==0:
        print('"%s" Network adapter has been successfully disabled'%(i))
        if out:
            print(out.strip())
    else:
        if err:
            print(err.strip())
        else:
            print('something went wrong when disabling "%s"'%(i))
            print(ret)

    
