手动调节,内网外网同时使用

内网外网同时使用的情况需要修改路由route ,但太麻烦,有时也不一定成功。其实只需要将其中一个网卡关闭,就可以使用另外一个网络。上程序,是不是很简单。

import os
import time
ret = os.system("ping baidu.com -n 1")
if ret == 0:
    print("OK")
    show_cmd = 'netsh interface show interface'
    disable_cmd = 'netsh interface set interface 以太网 disabled'   #关闭网卡
    os.system(disable_cmd)
    print("已成功关闭以太网·!可以使用内网")
    time.sleep(5)
else:
    print("NO")
    disable_cmd = 'netsh interface set interface 以太网 enabled'  # 恢复网卡
    os.system(disable_cmd)
    print("已成功打开以太网·!可以使用互联网")
    time.sleep(5)

具体DOS命令如下:

禁用无线网卡:netsh interface set interface wlan0 disabled

启用无线网卡:netsh interface set interface wlan0 enabled

禁用有线网卡:netsh interface set interface eth0 disabled

启用有线网卡:netsh interface set interface eth0 enabled

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值