获取被控 ipv6
win+r 输入 mstsc 打开远控 app、输入 ipv6
确定即可连接
利用 ddns 动态解析
做一个脚本,利用阿里云 api 更新域名指向最新的ipv6 ,每10分钟更新一次,这样子就不用担心网络重启后公网 ipv6 变化
添加解析记录
前提是有自己的域名
然后在设置添加一条 ipv6 解析记录
查询该记录的信息:
https://api.aliyun.com/api/Alidns/2015-01-09/DescribeDomainRecords
定时脚本更新
这个需要阿里云的访问密钥,在账户设置可以查到
AccessKey ID
xxxxxxxxxxxx
AccessKey Secret
xxxxxxxxxxxxxxx
脚本如下:自己输入自己的配置信息:
# pip 安装依赖
pip install alibabacloud_alidns20150109==3.0.7
查询
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import os
import socket
import sys
from typing import List
from alibabacloud_alidns20150109.client import Client as Alidns20150109Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_alidns20150109 import models as alidns_20150109_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> Alidns20150109Client:
"""
使用AK&SK初始化账号Client
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,您的 AccessKey ID,
access_key_id=access_key_id,
# 必填,您的 AccessKey Secret,
access_key_secret=access_key_secret
)
# Endpoint 请参考 https://api.aliyun.com/product/Alidns
config.endpoint = f'alidns.cn-hangzhou.aliyuncs.com'
return Alidns20150109Client(config)
@staticmethod
def get_ipv6():
host_ipv6 = []
ips = socket.getaddrinfo(socket.gethostname(), 80)
for ip in ips:
if ip[4][0].startswith('24'):
# 2408 中国联通
# 2409 中国移动
# 240e 中国电信
# print(ip[4][0])
host_ipv6.append(ip[4][0])
res = ''
# for ip_str in host_ipv6:
# if len(ip_str) > len(res):
# res = ip_str
if host_ipv6.__sizeof__() > 0:
res = host_ipv6[0]
return res
@staticmethod
def main(
args: List[str],
) -> None:
# 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
client = Sample.create_client(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
update_domain_record_request = alidns_20150109_models.UpdateDomainRecordRequest(
record_id='根据api查询到的',
type='AAAA',
rr='自己的域名前缀',
value=Sample.get_ipv6()
)
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
print(update_domain_record_request)
print("发送更新请求")
client.update_domain_record_with_options(update_domain_record_request, runtime)
print("发送更新请求成功")
except Exception as error:
# 如有需要,请打印 error
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
os.environ.setdefault('ALIBABA_CLOUD_ACCESS_KEY_ID', "xxxxxxxxxxxxx")
os.environ.setdefault('ALIBABA_CLOUD_ACCESS_KEY_SECRET', "xxxxxxxxxxxxxxx")
Sample.main(sys.argv[1:])
解决运行时弹窗黑框问题:
使用vbs套个后台的壳,在同目录下新建一个文件 start.vbs
set ws=wscript.createobject("wscript.shell")
ws.run "python C:\Users\xxxx\Desktop\ComTools\updateIPv6\update-ipv6.py",0
windows 使用schtasks定时运行,linux 使用 crontab:
schtasks /create /sc minute /mo 20 /tn "updateipv6-" /tr "C:\Users\xxx\Desktop\ComTools\updateIPv6\start.vbs"
linux 参考这个: