代码片段1

原创
2017/05/23 09:19
阅读数 94

定时关闭windows网络

import os
import time
from datetime import datetime, timedelta

import logging
import random

if __name__ == '__main__':
    logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    time_now = datetime.now()
    time_shutdown = time_now.replace(hour=5, minute=54)
    if time_shutdown < time_now:
        time_shutdown = time_shutdown + timedelta(days=1)

    sleep_secs = (time_shutdown-time_now).seconds

    logging.error('>>>>> 将会在 {0} 关闭网络, 等待时间 {1} 秒'.format(time_shutdown.strftime('%Y-%m-%d %H:%M:%S'), sleep_secs))
    time.sleep( sleep_secs )

    logging.error('>>>>> 关闭网络')
    os.system('ipconfig /release')


    time_now = datetime.now()
    time_start = time_now.replace(hour=8, minute=int(random.uniform(45, 58)))
    if time_start < time_now:
        time_start = time_start + timedelta(days=1)

    sleep_secs = (time_start-time_now).seconds

    logging.error('>>>>> 将会在 {0} 启用网络, 等待时间 {1} 秒'.format(time_start.strftime('%Y-%m-%d %H:%M:%S'), sleep_secs))
    time.sleep( sleep_secs )

    logging.error('启用网络')
    os.system('ipconfig /renew')


展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部