|
从4月1日来到矿渣后,就仿佛打开了新世界,经常折腾到深夜,然后第二天伴随着黑眼圈和唠叨出门...- e/ n' w1 s9 Q, P# v
明天,对了就是明天 又少不了一顿臭骂...' E9 f3 Q# t* Q$ `
! N; F r H7 i5 W O% D
百度搜到一大佬在张大妈上发布的aliddns教程,按照他的照抄结果脚本把内网ipv6地址传上去了,+ z3 E1 M# l. S- P9 L" @8 g, o
3 m5 z: ?( S* H, Q% G
" a0 ^8 K3 D2 E8 I) I# e: M% r
仔细一看他的教程中 ipv6地址栏 第一行地址就是外网地址,而我的是内网地址,5 J6 A2 _& m4 g' K- ]
瞎子过河改了第20行 print $2 不行,33行tail -n4也不行,
* G3 @, R/ g; B1 c# {! m9 ~菜鸟看不懂代码,也不知道去哪问,希望能有路过的大神能指点下
. y H" B4 ~, z6 s9 \9 j, |( W6 g) E% S% P. g
0 a9 \5 U1 h) P1 F ~
: I5 n' D- k7 U! S, f+ q1 u( ^
0 K% f9 d: g$ d1 C* W: P) _0 t# n0 a2 f" P# `
- aliddnsipv6_ak="aliddns_id"- p2 E' m2 h% L M
- aliddnsipv6_sk="password_info"8 W6 y9 @! i u8 n- ~7 G
- aliddnsipv6_name1='nas'
6 b+ a9 @; B u& b& S- b; A, P - aliddnsipv6_domain='mydomain.cn'
+ ]& B% z( r R# Z4 R4 b. i - aliddnsipv6_ttl="600"
9 J: j& j8 C9 ~, B# F - - d0 J" \7 z0 L
- if [ "$aliddnsipv6_name1" = "@" ]
5 l7 @2 o, S5 E/ Q6 E - then
5 O# I V6 O* e! S0 S& @ - aliddnsipv6_name=$aliddnsipv6_domain
- s6 T/ [% n1 t/ n8 h" S - else* u( d# V4 j0 t% T
- aliddnsipv6_name=$aliddnsipv6_name1.$aliddnsipv6_domain3 i6 A% X, {4 _
- fi. G% u3 t. g1 h/ Y" a& }3 D
- , u6 `$ n4 J& |
- now=`date` q1 [! s I: L. j: t1 G$ E
q6 A- `. S3 |3 ]- die () {% s9 U9 ?2 Z3 X; k1 h/ G
- echo $1% {, u) a4 P1 r/ o* R% R3 ^
- }
6 o2 [- h) f! y2 Q - - P9 W' X' K/ A4 X; }
- ipv6s=`ip addr show eth0 | grep "inet6.*global" | awk '{print $1}' | awk -F"/" '{print $1}'` || die "$ipv6"
+ L/ c$ a0 c T7 F' K
, w3 }# g8 \. N2 L/ _9 c% k! q- for ipv6 in $ipv6s
$ L+ q( S9 X; G. ^) H# ] - do$ E6 g$ X$ f0 S% u( p3 e
- #ipv6 = $ipv6! X- B3 v# `% [
- break: ]2 [/ t4 h$ v5 Y0 L% {
- done: p ~' m+ n! _
- : g, `, a2 j; [6 r k0 _
- echo $ipv6- }. f7 H! a' J, W
4 L1 {( S1 k3 @& s- current_ipv6=`nslookup -query=AAAA $aliddnsipv6_name 2>&1`) p# u5 k& K- \8 d, Q H9 R8 c: l0 P
- #echo $current_ipv6
/ B3 ~' ?% Q8 l
9 r ~" E! ?2 g' I- current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'` b- f+ b0 e8 q- ~
- echo $current_ipv6- k! i0 Y( ~: i$ G3 I
/ A0 B0 f( }! Z3 g* o: \- if [ "$?" -eq "0" ]
3 W0 a2 z2 Z; M. ^# Y" O. u - then3 h6 ^' ~/ s6 N
- current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'`
1 C- H6 ], J% g" v3 A& { - echo $current_ipv6! [ B! d$ T* U2 V0 A
) k& |3 q7 U- ~" @ l- if [ "$ipv6" = "$current_ipv6" ]2 B) R( Z0 E9 X
- then: q$ g. x3 E9 |' T$ {3 A
- echo "skipping"( U7 N, g( ~& t0 N
- fi 4 G5 i8 o" c8 P+ z
- # fix when A record removed by manual dns is always update error
# k1 g3 b! o S; |/ G( V$ C - else) V4 | F# y, n1 F5 t5 H5 R
- unset aliddnsipv6_record_id0 N$ l' c. Q0 X. E: T, A) O' `3 x
- fi
8 ?' M' k+ H. c2 O( [6 T - # t0 [ b3 S1 b" l A; H# s4 M% N
- , @ g# ~6 J' p& C
- timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`- K6 k% y N, x0 ^1 m. H. C
- + v( f) o6 z: t: M! D' W
- " L- P' O( M" } h: }
- urlencode() {
4 N4 B) r6 K' T8 E4 l# ~* {( U- ^ - # urlencode <string>
- k* u8 \ Q# T - out=""
$ d: K" b/ i, p1 i" A8 T7 E - while read -n1 c5 L; A) `( S$ X$ P# E" ]
- do/ B: S6 c9 i. i2 m0 t$ {
- case $c in
& Z* F/ U8 _. ] - [a-zA-Z0-9._-]) out="$out$c" ;;
6 b5 f* ~2 p, y$ ^$ s! Q% B9 N! E - *) out="$out`printf '%%%02X' "'$c"`" ;;; M) M0 \# q. X3 d* P/ p2 t2 l" u
- esac
* B/ d+ v0 y# p0 B( e Q! o - done
' ^7 W7 L" |' R: d6 C7 ^3 x - echo -n $out
' P/ e3 g2 ?% z) d, Z# W, | - }3 \' f9 w# o. g4 o/ d A+ O0 d
' I" \. ] r7 O! F- enc() {
, k0 A' J8 w$ e5 l* f - echo -n "$1" | urlencode
a8 g! G L. }+ D" A1 g - }7 \- T7 Z8 c2 B" K% z' s7 \
- 6 S5 V* o! N/ c6 o5 Z
- send_request() {4 l' x( [: P! z, D- i
- local args="AccessKeyId=$aliddnsipv6_ak&Action=$1&Format=json&$2&Version=2015-01-09"
6 k; e0 N4 H" b; Q! k - local hash=$(echo -n "GET&%2F&$(enc "$args")" | openssl dgst -sha1 -hmac "$aliddnsipv6_sk&" -binary | openssl base64)2 M- I$ l' ~5 N7 N' m" J9 W
- curl -s "http://alidns.aliyuncs.com/?$args&Signature=$(enc "$hash")"6 u+ c& Q6 D. N. T% u8 B: J" o; }/ p+ |
- }
" Z( m( U$ W- E3 ]. f - p# r' Z" E% m* _5 o; j
- get_recordid() {
# c( t. P" e: H; `! g5 O' o8 y ` - grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'
3 h) Y4 V7 V: l$ N: g+ c8 i: q1 E - }6 z1 b: E4 l" a' H2 W) z, b
9 X$ L7 ^1 i' t6 n( P2 ?' I+ F- query_recordid() {
, S5 v& `: G: D% c6 B o* V - send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddnsipv6_name&Timestamp=$timestamp&Type=AAAA"2 Z3 C8 Z# {' Y+ g: T4 z% x, ~8 ]
- }3 @# U" B: f( C4 h1 h% P
- 1 D; O3 F3 R1 L c* x F, y
- update_record() {2 {* J d8 r% V, a7 f0 f
- send_request "UpdateDomainRecord" "RR=$aliddnsipv6_name1&RecordId=$1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"3 f' c' j" [6 L' s: s& m
- }
9 M8 s. |. k9 y6 _! D" Q" F9 q - / u, f% W! J4 p" I$ ]3 u
- add_record() {7 S( U9 ^5 e. _: n
- send_request "AddDomainRecord&DomainName=$aliddnsipv6_domain" "RR=$aliddnsipv6_name1&SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&TTL=$aliddnsipv6_ttl&Timestamp=$timestamp&Type=AAAA&Value=$(enc $ipv6)"
/ _9 Q$ y& |: p# t - }2 {9 S1 u2 _, W( P+ i* ^
- 4 o1 o3 H& d+ H& N
- #add support */%2A and @/%40 record
" g5 X* O( {" Z8 F0 Q0 q& r; A - 3 I! R; b. X1 e) \/ h! p( r% ?0 ?$ `
- ; m* ` ~/ y5 [
- if [ "$aliddnsipv6_record_id" = "" ]
, j+ Z1 ~; }8 M/ f - then0 v# q8 b6 I/ _* H5 `) [& \, `' p
- aliddnsipv6_record_id=`query_recordid | get_recordid`
% Z5 ^9 o0 I2 Z |6 h - #echo '-----------------' $aliddnsipv6_record_id
6 v) r3 s* j% n3 S. _3 ` - fi
6 r5 J- @' C, q8 Z7 X, } - if [ "$aliddnsipv6_record_id" = "" ], f0 M& @4 k. \
- then
' `# k Z) Y& ]) q- S& p - aliddnsipv6_record_id=`add_record | get_recordid`2 n" W' u( f9 A% P' g) ]/ O
- echo "added record $aliddnsipv6_record_id"
: T2 t: J; K* r: Z1 N/ g - else
P" T9 ~; Y- b6 {2 p0 ^4 e/ Z - update_record $aliddnsipv6_record_id
0 a0 h& `3 C$ L - echo "updated record $aliddnsipv6_record_id"; A+ G, a1 V H/ }) Q6 b* c) C
- fi1 M5 C6 D" F9 }2 r1 V/ [: c+ K
$ ?+ o0 W% [& m0 ?
复制代码
1 J' P) O0 U8 t% a" r! S2 {+ `7 ]+ s/ O& y: j
% G& V' ~3 Y% F5 ^2 T+ ] |
|