#!/bin/sh
get_local_ipv4(){
# echo hello
case ${1} in
"curl")
local bin="curl -4fsS"
;;
"wget")
local bin="wget -O- -4"
;;
*)
echo "Error command_type" 1>&2
1>&2
rm $history_file
exit 1
;;
esac
$bin "http://ip-api.com/json/?fields=query" 2>/dev/null | cut -d ":" -f 2 | sed -e "s/[\"}]//g"
}
get_local_ipv6(){
local devices=$1
ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1
}
get_linux_ipv4(){
local user=$1
local password=$2
local ip=$3
local port=$4
local login_type=$5
local bin_type=$6
case $login_type in
"key")
if [ -r "$key" ]; then
local connect="ssh ${user}@${ip} -p $port -i"
else
local connect="ssh ${user}@${ip} -p $port"
fi
;;
"password")
local connect="sshpass -p $password ssh ${user}@${ip} -p $port"
;;
*)
echo "Error login_type" 1>&2
1>&2
rm $history_file
exit 1
;;
esac
case $bin_type in
"curl")
local bin="curl -4fsS http://ip-api.com/json/?fields=query 2>/dev/null"
;;
"wget")
local bin="wget -4 -O- http://ip-api.com/json/?fields=query 2>/dev/null"
;;
*)
echo "Error command_type" 1>&2
1>&2
rm $history_file
exit 1
;;
esac
$connect "$key" $bin | cut -d ":" -f 2 | sed -e "s/[\"}]//g"
}
get_linux_ipv6(){
local user=$1
local password=$2
local ip=$3
local port=$4
local login_type=$5
local device=$6
case $login_type in
"key")
if [ -r "$key" ]; then
local connect="ssh ${user}@${ip} -p $port -i"
else
local connect="ssh ${user}@${ip} -p $port"
fi
;;
"password")
local connect="sshpass -p $password ssh ${user}@${ip} -p $port"
;;
*)
echo "Error login_type" 1>&2
rm $history_file
exit 1
;;
esac
local bin="ip -6 addr list scope global $device"
$connect "$key" $bin | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1
}
get_windows_ipv4(){
local user=$1
local password=$2
local ip=$3
local port=$4
local login_type=$5
local bin_type=$6
case $login_type in
"key")
if [ -r "$key" ]; then
local connect="ssh ${user}@${ip} -p $port -i"
else
local connect="ssh ${user}@${ip} -p $port"
fi
;;
"password")
local connect="sshpass -p $password ssh ${user}@${ip} -p $port"
;;
*)
echo "Error login_type" 1>&2
1>&2
rm $history_file
exit 1
;;
esac
case $bin_type in
"curl")
local bin="curl -4fsS http://ip-api.com/json/?fields=query"
;;
"wget")
local bin="wget -4 -O- -q http://ip-api.com/json/?fields=query"
;;
*)
echo "Error command_type"
rm $history_file
exit 1
;;
esac
$connect "$key" $bin | cut -d ":" -f 2 | sed -e "s/[\"}]//g"
}
get_windows_ipv6(){
local user=$1
local password=$2
local ip=$3
local port=$4
local login_type=$5
local device=$6
case $login_type in
"key")
if [ -r "$key" ]; then
local connect="ssh ${user}@${ip} -p $port -i"
else
local connect="ssh ${user}@${ip} -p $port"
fi
;;
"password")
local connect="sshpass -p $password ssh ${user}@${ip} -p $port"
;;
*)
echo "Error login_type" 1>&2
1>&2
rm $history_file
exit 1
;;
esac
info=$($connect "$key" "chcp 437 & ipconfig /all")
if [ -z "$device" ]; then
echo "$info" | sed -e "s/^[[:alnum:]].*//g" -e "s/^[[:blank:]]*//g" | grep "Preferred" | grep "IPv6 Address" | grep -v "Link-local" | sed -n -e "1p" | sed -e "s/^.*: //g" -e "s/(.*)//g" -e "s/[[:blank:]]*//g" -e "s/\r//g"
else
temp=$(echo "$info" | grep "^[[:alnum:]]" -n | grep "${device}:" -A 1)
local device_start=$(echo "$temp" | sed -n -e "1p" | cut -d ":" -f 1)
local device_end=$(($(echo "$temp" | sed -n -e "2p" | cut -d ":" -f 1)-1))
unset temp
if [ -z "$device_start" ]; then
echo "No device found!" 1>&2
else
test "$device_end" = "-1" && device_end=$(echo "$info" | wc -l)
echo "$info" | sed -n -e "$(($device_start+1)),$device_end p" | sed -e "s/^[[:blank:]]*//g" | grep "Preferred" | grep "IPv6 Address" | grep -v "Link-local" | sed -n -e "1p" | sed -e "s/^.*: //g" -e "s/(.*)//g" -e "s/[[:blank:]]*//g" -e "s/\r//g"
fi
fi
}
get_esxi_ipv4(){
local user=$1
local password=$2
local ip=$3
local port=$4
local login_type=$5
case $login_type in
"key")
if [ -r "$key" ]; then
local connect="ssh ${user}@${ip} -p $port -i"
else
local connect="ssh ${user}@${ip} -p $port"
fi
;;
"password")
local connect="sshpass -p $password ssh ${user}@${ip} -p $port"
;;
*)
echo "Error login_type" 1>&2
1>&2
rm $history_file
exit 1
;;
esac
local bin="wget -O- http://ip-api.com/json/?fields=query 2>/dev/null"
$connect "$key" $bin | cut -d ":" -f 2 | sed -e "s/[\"}]//g"
}
get_esxi_ipv6(){
local user=$1
local password=$2
local ip=$3
local port=$4
local login_type=$5
local device=$6
case $login_type in
"key")
if [ -r "$key" ]; then
local connect="ssh ${user}@${ip} -p $port -i"
else
local connect="ssh ${user}@${ip} -p $port"
fi
;;
"password")
local connect="sshpass -p $password ssh ${user}@${ip} -p $port"
;;
*)
echo "Error login_type" 1>&2
rm $history_file
exit 1
;;
esac
info=$($connect "$key" "esxcli network ip interface ipv6 address list")
if [ -z "$device" ]; then
echo "$info" | grep "PREFERRED" | grep -v "[[:blank:]]fe" | sed -n "1p" | awk '{printf $2 "\n"}'
else
device_info=$(echo "$info" | grep "^$device" || echo "")
if [ -z "$device_info" ]; then
echo "No device found!" 1>&2
else
echo "$device_info" | grep "PREFERRED" | grep -v "[[:blank:]]fe" | sed -n "1p" | awk '{printf $2 "\n"}'
fi
fi
}
zone_ipv4_update(){
if [ -r "$dynv6_key" ]; then
ssh api@$dynv6_server -i "$dynv6_key" "hosts $common_zone set ipv4addr $zone_ipv4"
else
ssh api@$dynv6_server "hosts $common_zone set ipv4addr $zone_ipv4"
fi
}
zone_ipv6_update(){
if [ -r "$dynv6_key" ]; then
ssh api@$dynv6_server -i "$dynv6_key" "hosts $common_zone set ipv6addr $zone_ipv6"
else
ssh api@$dynv6_server "hosts $common_zone set ipv6addr $zone_ipv6"
fi
# echo "v6 Update disable"
}
host_ipv4_update(){
if [ -r "$dynv6_key" ]; then
ssh api@$dynv6_server -i "$dynv6_key" "hosts $common_zone records set $1 a addr $2"
else
ssh api@$dynv6_server "hosts $common_zone records set $1 a addr $2"
fi
# echo "v4 Update disable"
}
host_ipv6_update(){
if [ -r "$dynv6_key" ]; then
ssh api@$dynv6_server -i "$dynv6_key" "hosts $common_zone records set $1 aaaa addr $2"
else
ssh api@$dynv6_server "hosts $common_zone records set $1 aaaa addr $2
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
动态域名内网穿透 前言 我们会有这样的需求,就是在外时能够访问自己家中的电脑,但是家中电脑的IP又是动态的。这时候我们就需要使用动态域名映射去解决我们的问题 由于本人由自己几个低功耗机子,但是不喜欢单独拿一个装openwrt啥的,都是装的centos,所以选择比较轻量方式实现,所以选择如下方式,自己机器只有shell脚本和定时任务。我自己是有备案的腾讯云域名,所以选择了第一种方式,第二种方式则完全免费。 实现 优点 缺点 **方式一:**腾讯云DNS服务 + Shell脚本 稳定、快速、域名名称由自己喜好选择 域名收费 **方式二:**dynv6DDNS服务 + Shell脚本 完全免费 只能填二级域名,注册稍微麻烦 ———————————————— 版权声明:本文为CSDN博主「程序员知码」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/A10714075/article/details/123960344
资源推荐
资源详情
资源评论
收起资源包目录
ddns脚本.zip (3个子文件)
dynv6
ddns.sh 27KB
ddns.conf 402B
腾讯云
ddns.sh 1KB
共 3 条
- 1
资源评论
tjsoft
- 粉丝: 397
- 资源: 751
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功