Skip to content

Instantly share code, notes, and snippets.

@renorzr
Last active August 3, 2020 17:27
Show Gist options
  • Select an option

  • Save renorzr/7209586 to your computer and use it in GitHub Desktop.

Select an option

Save renorzr/7209586 to your computer and use it in GitHub Desktop.
get mac address
# -*- coding: utf-8 -*-
import locale
import random
import _winreg
import subprocess
import socket
import time
SUBKEY = r'SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001'
def set(value):
update_registry(value)
restart_network()
wait_up()
def update_registry(value):
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, SUBKEY, 0, _winreg.KEY_ALL_ACCESS) as key:
_winreg.SetValueEx(key, 'NetworkAddress', 0, _winreg.REG_SZ, value)
def restart_network():
shell(u'netsh interface set interface 本地连接 disabled')
shell(u'netsh interface set interface 本地连接 enabled')
def shell(command):
subprocess.call(command.encode(locale.getpreferredencoding()).split(' '))
def new():
value = rand()
print value
set(value)
return value
def rand():
return '0800%08x' % random.randint(0, 0xffffffff)
def wait_up():
hostname = socket.gethostname()
while socket.gethostbyname(hostname) == '127.0.0.1':
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment