SHARE
TWEET

Untitled

a guest Jun 27th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import subprocess
  2. import time # for test
  3.  
  4. def get_connected_network_interface_name():
  5.     netsh_command = subprocess.Popen(['netsh', 'interface', 'show', 'interface'], stdout=subprocess.PIPE)
  6.     is_interface_name_lines = False
  7.     for netsh_output_line in netsh_command.stdout:
  8.         if netsh_output_line == b'-------------------------------------------------------------------------\r\n':
  9.             is_interface_name_lines = True
  10.             continue
  11.         if is_interface_name_lines:
  12.             interface_info_text = netsh_output_line.decode('utf-8')
  13.             interface_info_struct = interface_info_text.split()
  14.             if interface_info_struct[1] == 'Connected':
  15.                 return interface_info_struct[3]
  16.     return ''
  17.  
  18. def disconnect_network_interface(name):
  19.     netsh_commend = subprocess.Popen(['netsh', 'interface', 'set', 'interface', name, 'disabled'])
  20.  
  21. def connect_network_interface(name):
  22.     netsh_commend = subprocess.Popen(['netsh', 'interface', 'set', 'interface', name, 'enabled'])
  23.  
  24. def main():
  25.     interface_name = get_connected_network_interface_name()
  26.     print(interface_name)
  27.     disconnect_network_interface(interface_name)
  28.     time.sleep(10)
  29.     connect_network_interface(interface_name)
  30.  
  31. if __name__ == '__main__':
  32.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top