跳到主要内容

10 篇博文 含有标签「内网穿透」

查看所有标签

结合阿里云DNS实现动态DNS

· 阅读需 3 分钟

动态DNS 实现

项目已放Github,欢迎Star。 https://github.com/MasonSRE/ddns

编写脚本获取公网IP地址,实时更新DNS记录

编写 get_ip_dns.py

import time
import logging
import requests
import json
from aliyunsdkcore.client import AcsClient
from aliyunsdkalidns.request.v20150109 import UpdateDomainRecordRequest
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkalidns.request.v20150109 import DescribeDomainRecordsRequest, DescribeDomainRecordInfoRequest


# 阿里云API凭证
access_key_id = 'your_access_key_id'
access_key_secret = 'your_access_key_secret'
region_id = 'cn-hangzhou' # 你的阿里云区域ID (可以不做修改)

# 域名和记录信息
domain_name = 'example.com' # 你的域名
sub_domain = 'www' # 子域名,例如www

# 设置日志记录
logging.basicConfig(level=logging.INFO)

def get_public_ip():
try:
response = requests.get('https://api.ipify.org?format=json')
response.raise_for_status() # 抛出HTTP错误
ip = response.json()['ip']
logging.info(f'Public IP retrieved: {ip}')
return ip
except requests.exceptions.RequestException as e:
logging.error(f'Failed to retrieve public IP: {e}')
return None

def get_current_dns_record(client, domain_name, sub_domain):
request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest()
request.set_DomainName(domain_name)
try:
response = client.do_action_with_exception(request)
records = json.loads(response)['DomainRecords']['Record']
for record in records:
if record['RR'] == sub_domain and record['Type'] == 'A':
return record['RecordId'], record['Value']
return None, None
except ServerException as e:
logging.error(f'Failed to get the current DNS record: {e}')
return None, None

def update_dns_record(client, record_id, sub_domain, ip):
request = UpdateDomainRecordRequest.UpdateDomainRecordRequest()
request.set_RecordId(record_id)
request.set_RR(sub_domain)
request.set_Type('A')
request.set_Value(ip)
try:
client.do_action_with_exception(request)
logging.info(f'Updated DNS record to {ip}')
except ServerException as e:
logging.error(f'Failed to update DNS record: {e}')

def add_dns_record(client, domain_name, sub_domain, ip):
request = AddDomainRecordRequest.AddDomainRecordRequest()
request.set_DomainName(domain_name)
request.set_RR(sub_domain)
request.set_Type('A')
request.set_Value(ip)
try:
client.do_action_with_exception(request)
logging.info(f'Added DNS record: {sub_domain}.{domain_name} -> {ip}')
except ServerException as e:
logging.error(f'Failed to add DNS record: {e}')

def update_dns_record_if_needed(client, domain_name, sub_domain, new_ip):
record_id, current_ip = get_current_dns_record(client, domain_name, sub_domain)
if record_id is None:
logging.warning(f'No existing DNS record found for {sub_domain}.{domain_name}, adding a new record.')
add_dns_record(client, domain_name, sub_domain, new_ip)
return
if current_ip != new_ip:
update_dns_record(client, record_id, sub_domain, new_ip)

def main():
client = AcsClient(access_key_id, access_key_secret, region_id)

while True:
new_ip = get_public_ip()
if new_ip is not None:
update_dns_record_if_needed(client, domain_name, sub_domain, new_ip)
time.sleep(10) # 等待10秒再检查

if __name__ == '__main__':
main()

检查公网IP并更新 DNS 纪录

此脚本将获取该服务器的公网IP,并且修改阿里云对应的DNS解析的A纪录。

  • 非常适用于家用网络,公网IP改变时也会同步修改至Aliyun dns解析
  • 手动误修改此DNS解析时,也会进行操作IP对比,同时进行修改 dns 解析

1、下载依赖包

pip3 install requests
pip3 install aliyun-python-sdk-core
pip3 install aliyun-python-sdk-alidns

2、修改配置

# 阿里云API凭证
access_key_id = 'your_access_key_id'
access_key_secret = 'your_access_key_secret'
region_id = 'cn-hangzhou' # 你的阿里云区域ID(可以不做修改)

# 域名和记录信息
domain_name = 'example.com' # 你的域名
sub_domain = 'www' # 子域名,例如www

3、运行脚本

python3 get_ip_dns.py

Netbird 组网搭建

· 阅读需 3 分钟

Netbird 组网搭建

官网文档:https://github.com/netbirdio/netbird

搞这个平台是因为之前遇到了很多网络链接上面的问题,在公司用家里虚拟化的 N 多个虚拟机测试时,很不方便。

还有就是在家连接公司的局域网时还要留个口子,总感觉很麻烦。现在用 Netbird 完全解决了这个问题

Netbird 自建平台

前置条件:

  • 一个拥有公网 IP 的 Linux 服务器;

  • Docker 与 docker-compose;

  • 开放 TCP 端口 80, 443, 33073, 10000(端口不可被占用);

  • 开放 UDP 端口 3478, 49152-65535

  • 配置好了 DNS 解析

mkdir netbird && cd netbird

# 前置安装软件
yum install jq && yum install curl
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce-20.10.12 -y
systemctl enable docker && systemctl start docker
wget https://github.com/docker/compose/releases/download/1.28.6/docker-compose-Linux-x86_64
chmod +x docker-compose-Linux-x86_64
mv docker-compose-Linux-x86_64 /usr/local/sbin/docker-compose
docker-compose version

# 一键部署
export NETBIRD_DOMAIN=net.domain.com; curl -fsSL https://github.com/netbirdio/netbird/releases/latest/download/getting-started-with-zitadel.sh | bash

# 浏览器访问按照账号密码登陆即可

添加节点

官网文档:https://docs.netbird.io/how-to/getting-started#installation

Ubuntu/Debian
# Add the repository
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg -y
curl -sSL https://pkgs.netbird.io/debian/public.key | sudo gpg --dearmor --output /usr/share/keyrings/netbird-archive-keyring.gpg
echo 'deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main' | sudo tee /etc/apt/sources.list.d/netbird.list

# Update APT's cache
sudo apt-get update

# Install the package
# for CLI only
sudo apt-get install netbird
# for GUI package
sudo apt-get install netbird-ui

# 在主页面添加一个 Setup Keys
# Run NetBird and log in the browser
netbird up --management-url https://net.yuanhome.space:443 --setup-key <SETUP KEY>
RPM/Red hat
# Add the repository
vim /etc/yum.repos.d/netbird.repo
[netbird]
name=netbird
baseurl=https://pkgs.netbird.io/yum/
enabled=1
gpgcheck=0
gpgkey=https://pkgs.netbird.io/yum/repodata/repomd.xml.key
repo_gpgcheck=1

# Install the package
# for CLI only
sudo yum install netbird
# for GUI package
sudo yum install netbird-ui

# 在主页面添加一个 Setup Keys
# Run NetBird and log in the browser
netbird up --management-url https://net.yuanhome.space:443 --setup-key <SETUP KEY>

利用iproyal住宅IP使用chatgpt

· 阅读需 2 分钟

随着 ChatGPT 和其他 AI 聊天机器人的普及,许多用户希望能够通过不同的 IP 地址来访问这些服务,以确保隐私和安全。IPRoyal 是一个提供住宅 IP 代理服务的平台,可以帮助用户实现这一目标。在本文中,我们将探讨如何利用 IPRoyal 的住宅 IP 服务与 ChatGPT 进行交互。

1. 为什么要使用 IPRoyal 住宅 IP?

  • 隐私保护:通过使用代理 IP,您可以隐藏您的真实 IP 地址,从而保护您的在线隐私。
  • 地理限制绕过:某些服务可能会根据地理位置进行限制,使用 IPRoyal 可以帮助您绕过这些限制。
  • 负载均衡:如果您运行一个需要大量与 ChatGPT 交互的应用,使用多个 IP 可以帮助分散请求,减少单一 IP 的压力。

最最最主要的原因:使用 Clash 的机场IP,很容易被封号,兄弟我已经被封四五个号了,还有当时刚放开GPT-4权限,就拥有GPT-4权限的市场价值两三千的账号,都被封了!!!

2. 如何设置 IPRoyal 代理?

  1. 访问 IPRoyal 官方网站并注册账号。
  2. 选择合适的套餐并完成购买。
  3. 在控制面板中,找到您的代理 IP 和端口信息。
  4. 在您的应用或浏览器中,进入网络设置(或者安装插件),将代理服务器设置为 IPRoyal 提供的 IP 和端口。

因为我 chrome 使用的 SwitchyOmega 配合Gost和Clash来做的,并且经常来回切换网络和地址。所以为了代理地址稳定我个人是单独用的 Firefox 来访问 OpenAI 用的,用的是 FoxyProxy 的插件。

PS: 为什么用Gost了还要用住宅IP代理?因为Gost配合VPS做的代理,依然有可能会被OpenAI识别到并且封禁,因为市面上几乎所有的VPS都是数据中心的IP,会被标记到。

我用的住宅IP是买的新加坡的住宅IP,一个 IP 价格 5.2美刀 一个月,还有非常重要的一点:最好用正规卡充值,虚拟卡充值可能会遭遇退款并封禁账号。

Chatgpt