Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import time # for test
- def get_connected_network_interface_name():
- netsh_command = subprocess.Popen(['netsh', 'interface', 'show', 'interface'], stdout=subprocess.PIPE)
- is_interface_name_lines = False
- for netsh_output_line in netsh_command.stdout:
- if netsh_output_line == b'-------------------------------------------------------------------------\r\n':
- is_interface_name_lines = True
- continue
- if is_interface_name_lines:
- interface_info_text = netsh_output_line.decode('utf-8')
- interface_info_struct = interface_info_text.split()
- if interface_info_struct[1] == 'Connected':
- return interface_info_struct[3]
- return ''
- def disconnect_network_interface(name):
- netsh_commend = subprocess.Popen(['netsh', 'interface', 'set', 'interface', name, 'disabled'])
- def connect_network_interface(name):
- netsh_commend = subprocess.Popen(['netsh', 'interface', 'set', 'interface', name, 'enabled'])
- def main():
- interface_name = get_connected_network_interface_name()
- print(interface_name)
- disconnect_network_interface(interface_name)
- time.sleep(10)
- connect_network_interface(interface_name)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement