zoukankan      html  css  js  c++  java
  • 工作笔记--Python自动切换host

    修改host代码:

    #coding:utf-8
    import os,time

    pwd = os.path.dirname(__file__) #获取当前文件夹的绝对路径
    pull_host_cmd = 'adb pull system/etc/hosts '+pwd
    push_host_cmd = 'adb push '+pwd+'hosts system/etc/'

    os.popen('adb root')
    temp = os.popen('adb remount')

    print 'Pull hosts..'
    temp = os.popen(pull_host_cmd)
    temp = temp.readline().split()

    #读取配置文件
    config_path = os.path.join(pwd, 'config.txt') #获取当前文件夹内的config文件
    config_file = open(config_path, "r") #读取文件

    #写追加方式打开host文件
    host_path = os.path.join(pwd,'hosts')
    host_file = open(host_path,"a+")

    for line in config_file:
    host_file.write(line)

    config_file.close() #关闭文件
    host_file.close()

    #push hosts
    temp = os.popen(push_host_cmd)
    temp = temp.readline().split()
    temp = os.system('del hosts')

    重置到localhost的代码:
    #coding:utf-8
    import os,time

    pwd = os.path.dirname(__file__) #获取当前文件夹的绝对路径
    pull_host_cmd = 'adb pull system/etc/hosts '+pwd
    push_host_cmd = 'adb push '+pwd+'hosts system/etc/'

    temp = os.popen(pull_host_cmd)
    temp = temp.readline().split()

    host_path = os.path.join(pwd,'hosts')
    host_file = open(host_path,"wb")

    host_file.write('127.0.0.1 localhost ')
    host_file.close()
    os.system('adb push hosts system/etc/hosts')
    os.system('del hosts')

    Project目录:

     

    
    
  • 相关阅读:
    webpack 知识点
    freemarker知识点
    js知识点
    oracle 安装介绍
    CentOS 7.4x64 系统安装完成后配置
    centos 7 互信【ssh】
    spark与mapreduce的最大区别和spark原理
    最简单的搭建SpringBoot框架步骤
    simplify(s)
    ezplot函数
  • 原文地址:https://www.cnblogs.com/ailiailan/p/7919470.html
Copyright © 2011-2022 走看看