python 之修改host配置

背景:生产环境登录 test.ai.com ,如果要登录验收的 test.ai.com 要改host配置,所以写了个python脚本

host生产环境配置为 #  192.163.0.0 test.ai.com

host验收环境为  192.163.0.0 test.ai.com

不加host配置默认是生成哈

import os
# C:\\Windows\\System32\\drivers\\etc\\hosts
os.chdir("C:\\Windows\\System32\\drivers\\etc")
print(os.getcwd())

temp = os.system("grep -i '192.163.0.0 test.ai.com' hosts")
temp1 = os.system("grep -i '# 192.163.0.0 test.ai.com' hosts")
if temp == 1:  # 没找到是新增
    print('新增')
    os.system("echo 192.163.0.0 test.ai.com >> hosts")
elif temp1 == 1:  # 没找到是验收要改生产
    print('改生产')
    print(os.system("sed -i 's/192.163.0.0 test.ai.com/# 192.163.0.0 test.ai.com/' hosts"))
else:  # 找到是生产要改验收
    print('改验收')
    print(os.system("sed -i 's/# 192.163.0.0 test.ai.com/192.163.0.0 test.ai.com/' hosts"))

相关推荐

  1. python 修改host配置

    2024-07-11 06:54:02       21 阅读
  2. ansible使用linefile批量修改网卡配置文件及host解析

    2024-07-11 06:54:02       32 阅读
  3. Linux下修改host文件

    2024-07-11 06:54:02       53 阅读
  4. Mac上配置host

    2024-07-11 06:54:02       34 阅读
  5. Python题解Leetcode Hot100技巧

    2024-07-11 06:54:02       19 阅读
  6. Python题解Leetcode Hot100回溯

    2024-07-11 06:54:02       14 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 06:54:02       53 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 06:54:02       55 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 06:54:02       46 阅读
  4. Python语言-面向对象

    2024-07-11 06:54:02       56 阅读

热门阅读

  1. 使用Python + Scrapy + Django构建企业级爬虫平台

    2024-07-11 06:54:02       22 阅读
  2. Elasticsearch 自定义评分和脚本评分

    2024-07-11 06:54:02       15 阅读
  3. CentOS 7 编译安装 sqlite3

    2024-07-11 06:54:02       18 阅读
  4. 面试题目分享

    2024-07-11 06:54:02       19 阅读
  5. ChatGPT 5.0:一年后的猜想

    2024-07-11 06:54:02       21 阅读
  6. Spring Boot集成pf4j实现插件开发功能

    2024-07-11 06:54:02       20 阅读