Last active
December 31, 2015 05:39
-
-
Save vladimirnani/7942329 to your computer and use it in GitHub Desktop.
Flips network connection in Windows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wmi | |
from _winreg import * | |
NETWORK_NAME = 'Local Area Connection' | |
REG_KEY = 'Software\Microsoft\Windows\CurrentVersion\Internet Settings' | |
def main(): | |
c = wmi.WMI() | |
key = OpenKey(HKEY_CURRENT_USER, REG_KEY, 0, KEY_WRITE) | |
adapter = [a for a in c.Win32_NetworkAdapter() | |
if a.NetConnectionID == NETWORK_NAME][0] | |
is_enabled = adapter.NetEnabled | |
if is_enabled: | |
adapter.Disable() | |
SetValueEx(key, "ProxyEnable", 0, REG_DWORD, 0) | |
print('Disabled') | |
else: | |
adapter.Enable() | |
SetValueEx(key, "ProxyEnable", 0, REG_DWORD, 1) | |
print('Enabled') | |
CloseKey(key) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment