Linux下使用python自动修改本机网关代码分享
#!/usr/bin/python
#autochangegatewayCreatedBymickelfeng
importos
importrandom,re
g='gateway192.168.1.'
rand=random.randint(1,3)
test='www.baidu.com'
command='/etc/init.d/networkingrestart'
GW="%s%d"%(g,rand)
PingTest='ping-c3'+test
try:
result=os.system(PingTest)
printresult
ifresult!=0:
data=open('/etc/network/interfaces').read()
data=re.sub('gateway192.168.1.*',GW,data)
open('/etc/network/interfaces','wb').write(data)
os.system(command)
os.system(command)
except:
pass热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短