Linux下使用python自動(dòng)修改本機(jī)網(wǎng)關(guān)代碼分享
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 14:41:23
Linux下使用python自動(dòng)修改本機(jī)網(wǎng)關(guān)代碼分享
Linux下使用python自動(dòng)修改本機(jī)網(wǎng)關(guān)代碼分享: #!/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
導(dǎo)讀Linux下使用python自動(dòng)修改本機(jī)網(wǎng)關(guān)代碼分享: #!/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
#!/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
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
Linux下使用python自動(dòng)修改本機(jī)網(wǎng)關(guān)代碼分享
Linux下使用python自動(dòng)修改本機(jī)網(wǎng)關(guān)代碼分享: #!/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