首先為pycharm配置管理員權限
image.png
修改網(wǎng)卡名字為英文字符
image.png
python+netsh控制網(wǎng)卡
import os
# 修改靜態(tài)ip
static = os.popen('netsh interface ipv4 set address "kc" static 192.168.0.166 255.255.255.0')
# 禁用網(wǎng)卡
diable = os.popen('netsh interface set interface "kc" admin=DISABLE')
# 啟用網(wǎng)卡
enable = os.popen('netsh interface set interface "kc" admin=ENABLE')
# 修改動態(tài)ip
dynamic = os.popen('netsh interface ipv4 set address "kc" dhcp')