Linux下使用python自动修改本机网关代码分享
Linux下使用python自动修改本机网关代码分享
发布时间:2016-12-28 来源:查字典编辑
摘要:#!/usr/bin/python#autochangegatewayCreatedBymickelfengimportosimportra...

#!/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

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新python学习
热门python学习
脚本专栏子分类