# -*- coding: utf-8 -*- # This file is auto-generated, don't edit it. Thanks. #pyinstaller --onefile your_script.py #创建虚拟环境venv: #python3 -m venv venv #依赖安装: #pip3 install --upgrade pip #pip3 install aliyun-python-sdk-dcdn==2.2.19 import os import sys import requests from typing import List import ast import subprocess import json from alibabacloud_dcdn20180115.client import Client as dcdn20180115Client from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_dcdn20180115 import models as dcdn_20180115_models from alibabacloud_tea_util import models as util_models from alibabacloud_tea_util.client import Client as UtilClient from datetime import datetime from urllib.request import urlopen import time import ssl import sys ssl._create_default_https_context = ssl._create_unverified_context def get_network_time(): url = "https://www.baidu.com" try: with urlopen(url) as res: utctime = gmtstr_to_localtime(res.getheader("Date")) return datetime_from_utc_to_local(utctime) except Exception as e: print("请检查网络设置") sys.exit() def gmtstr_to_localtime(gmtstr) -> datetime: return datetime.strptime(gmtstr, "%a, %d %b %Y %H:%M:%S GMT") def datetime_from_utc_to_local(utc_datetime): now_timestamp = time.time() offset = datetime.fromtimestamp(now_timestamp) - datetime.utcfromtimestamp( now_timestamp ) return utc_datetime + offset class Sample: def __init__(self): pass @staticmethod def create_client() -> dcdn20180115Client: """ 使用AK&SK初始化账号Client @return: Client @throws Exception """ # 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。 # 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378659.html。 config = open_api_models.Config( # 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。, access_key_id="LTAI5tPGKLFGsca3 ) # Endpoint 请参考 https://api.aliyun.com/product/dcdn config.endpoint = f'dcdn.aliyuncs.com' return dcdn20180115Client(config) @staticmethod def main( ) -> None: client = Sample.create_client() print("轮班自助his白名单ip添加工具,使用过程中任何问题联系运维QinRui") dm = 'pvip.hfkmyl.com' input_dm = input("请输入需要新增白名单域名:") print("需要配置白名单域名是:",input_dm) dm = input_dm describe_dcdn_domain_configs_request = dcdn_20180115_models.DescribeDcdnDomainConfigsRequest( domain_name=dm, function_names='ip_allow_list_set' ) runtime = util_models.RuntimeOptions() try: #1、先获取域名的ip白名单列表 result = client.describe_dcdn_domain_configs_with_options(describe_dcdn_domain_configs_request, runtime) default_ip_while_list = result.body.domain_configs.domain_config[0].function_args.function_arg[0].arg_value # 打印下获取的域名白名单ip地址段 print("当前查询的域名的ip白名单地址列表为:" + default_ip_while_list) # 提示用户输入 input_set_ip_while_list = input("请输入需要新增的ip白名单地址段,格式必须是ip或者ip地址段:") print("你输入的新增ip白名单为:", input_set_ip_while_list) #3、将输入的ip白名单列表和域名本身的ip白名单混在一起 # 将两个 IP 白名单地址转换为列表 default_ip_list = default_ip_while_list.split(',') input_ip_list = input_set_ip_while_list.split(',') # 合并这两个列表 merged_ip_list = default function_str = ''' [ { "functionArgs": [ { "argName": "ip_list", "argValue": "" } ], "functionName": "ip_allow_list_set" } ] ''' # 将字符串转换为 Python 对象 function_list = json.loads(function_str)tchSetDcdnDomainConfigsRequest( domain_names=dm, functions=updated_function_str ) #print(updated_function_str) ad1 = client.batch_set_dcdn UtilClient.assert_as_string(error.message) if __name__ == '__main__': #Sample.m html = response.text print("本次执行出口地址:",html) count = 1 def lock(): now = get_network_time() print(now) end_date = datetime(2025, 2, 27) if now > end_date: #print("g time.sleep(3) #'''
标签:set,ip,whiteip,list,datetime,input,白名单,import From: https://www.cnblogs.com/ruiy/p/18650198