Linux下使用python自动修改本机网关代码分享
更新时间:2015年05月21日 10:29:41 投稿:junjie
这篇文章主要介绍了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
相关文章
对numpy中的transpose和swapaxes函数详解
今天小编就为大家分享一篇对numpy中的transpose和swapaxes函数详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2018-08-08python Matplotlib数据可视化(2):详解三大容器对象与常用设置
这篇文章主要介绍了python Matplotlib三大容器对象与常用设置的相关资料,帮助大家更好的学习和使用Matplotlib库的用法,感兴趣的朋友可以了解下2020-09-09
最新评论