源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Linux下使用python自动修改本机网关代码分享

  • 时间:2020-09-23 17:33 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Linux下使用python自动修改本机网关代码分享
#!/usr/bin/python
#auto change gateway Created By mickelfeng
import os
import random,re
g='gateway 192.168.1.'
rand=random.randint(1,3)
test='www.baidu.com'
command='/etc/init.d/networking restart'
GW = "%s%d"%(g,rand)
PingTest = 'ping -c 3 ' + test
try:
  result=os.system(PingTest)
  print result
  if result!=0:
    data = open('/etc/network/interfaces').read()
    data = re.sub('gateway 192.168.1.*',GW, data)
    open('/etc/network/interfaces', 'wb').write(data)
    os.system(command)
    os.system(command)
except:
  pass
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部