|
从4月1日来到矿渣后,就仿佛打开了新世界,经常折腾到深夜,然后第二天伴随着黑眼圈和唠叨出门...
8 q5 [, r2 U, ?, X4 ^0 L明天,对了就是明天 又少不了一顿臭骂...
0 {3 |; X+ Z3 X/ {; Z
. k/ T! E, |( f7 l5 f百度搜到一大佬在张大妈上发布的aliddns教程,按照他的照抄结果脚本把内网ipv6地址传上去了,- B5 ?9 W/ j9 Q1 {) P
+ n! w6 i) {* I0 P1 Y! x1 @ h) F+ `2 a# Q8 s
仔细一看他的教程中 ipv6地址栏 第一行地址就是外网地址,而我的是内网地址,1 @# \; F1 a4 A: ]9 ~
瞎子过河改了第20行 print $2 不行,33行tail -n4也不行,+ H* i+ G; Y. o& [
菜鸟看不懂代码,也不知道去哪问,希望能有路过的大神能指点下
/ E) E5 E% W# j% v
^, i3 k; F# v8 k! I" o Q# a* ?/ j; I* @( @
4 b& {7 }0 B& i5 I, z
& ^( G' g1 E! f' r' _; u2 ^' _. o4 v# {* ~
- aliddnsipv6_ak="aliddns_id"
9 f3 n( u+ q+ Z2 r% h; A% i9 k - aliddnsipv6_sk="password_info"+ \% N8 y* G* {$ c- l
- aliddnsipv6_name1='nas'
+ n/ ~0 ]; M# d8 l4 p - aliddnsipv6_domain='mydomain.cn'8 v% B B' X; U& U% s4 w' E
- aliddnsipv6_ttl="600"4 z# F/ i3 G) z, w- y J
- $ f$ j- ]7 {9 y8 k: r
- if [ "$aliddnsipv6_name1" = "@" ]" x4 a( j6 a5 P0 f2 ~. H/ A# {
- then1 }* K% f8 a ~. E
- aliddnsipv6_name=$aliddnsipv6_domain5 ~1 S. X. [: I1 ^) n3 a. V
- else
# y4 X# B9 Y# n% p! }2 ~; D/ b - aliddnsipv6_name=$aliddnsipv6_name1.$aliddnsipv6_domain
" l: V) v9 y+ B3 h0 Y; u - fi
7 m' J0 @. m* k0 ]" Z - 8 L7 v: T, l$ j {
- now=`date`
) o2 H" N+ G- G9 ? - 1 y6 m( c. `6 ^* U, p* `
- die () {
t. l4 b( M; ?# Z$ q' | - echo $1
. c1 V. e- ] {7 ?* ^ - }
0 V2 ^5 y3 ?; _8 g2 h, M
3 b" ] k3 m/ S) l& `9 q4 u3 h- ipv6s=`ip addr show eth0 | grep "inet6.*global" | awk '{print $1}' | awk -F"/" '{print $1}'` || die "$ipv6"7 v3 n+ W2 ]9 [0 z0 K2 ~
- . w7 u, Y) a$ N
- for ipv6 in $ipv6s L7 g1 D8 n" a" S2 A/ @
- do
; P2 w/ B6 W& X" U8 Y% S - #ipv6 = $ipv6# C) _' ~6 ]1 A3 A7 `: l, ?
- break3 M* U7 b2 X! ~9 J! W% T p- r) u: l
- done
6 q k. \! Y0 G$ o" g0 e e - * s9 ^8 T8 M! u1 n/ I
- echo $ipv6: N' B/ L1 |8 Y( k, |
/ t8 z4 Y L l$ o/ E- current_ipv6=`nslookup -query=AAAA $aliddnsipv6_name 2>&1`% D+ m6 A3 Y7 ]( |6 N0 k
- #echo $current_ipv68 E+ n) z! f* ]4 a2 Z% I u
- / ^6 g1 H3 a& d# X6 L' ?
- current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'`( w' r+ W; e: [( Q8 Y
- echo $current_ipv6
) o+ y. F; x* W2 W& q8 [8 Q) l4 r - ; q4 \, W0 w$ i5 W' N
- if [ "$?" -eq "0" ], h* Y% _; s% C/ K! [$ s
- then! p5 B7 i* W# j7 ~5 d2 o" c
- current_ipv6=`echo "$current_ipv6" | grep 'Address: ' | tail -n1 | awk '{print $NF}'`8 c3 f1 d6 ^2 Q# `3 f1 Z w
- echo $current_ipv6
: R& t6 i7 W- @4 t9 Z
6 z9 B+ }! s) |7 I' B# G4 w% F2 _- if [ "$ipv6" = "$current_ipv6" ]
) y1 U% l1 m% H/ x/ ^ - then- Q7 o- _- Q3 g% Z
- echo "skipping"
- k+ {6 T" f' @ Y: Z - fi
; ^" y+ m2 B! c$ O6 f5 ? - # fix when A record removed by manual dns is always update error
" K n4 O# c1 I' H' E9 I/ W% z - else6 z' U; E3 m# }) g
- unset aliddnsipv6_record_id
/ I1 |' k- d' D" Q, t# h - fi
; |+ l" P( @, s! J2 Z1 X
8 Z) p) _! J' [5 L+ a/ z
% F: O% G, K; d6 P, {9 @0 P- timestamp=`date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ"`5 G2 w( u( k9 g. B# q
1 P, |( E! T. S) Y0 a/ k7 _$ M: y
1 G% s8 U j5 x( g$ M- urlencode() {
& l. l5 v( u- n" ?! B - # urlencode <string>
3 F* Y2 \2 X8 M7 R- `1 b& n. v- P6 Q - out=""( R' b' |5 Q P
- while read -n1 c8 H4 _0 r- `4 S7 F
- do
+ G. J& T( H& f: A8 j( D9 ?4 ] - case $c in4 L6 A) c9 l, v3 C# O2 J& q) l2 ]8 g
- [a-zA-Z0-9._-]) out="$out$c" ;;, S2 J- A/ F: ^1 k4 f# E
- *) out="$out`printf '%%%02X' "'$c"`" ;;
: i9 G. h* W- @) H9 x - esac$ P$ {8 O- c2 X. V5 F
- done) e2 N7 q& }$ T
- echo -n $out
/ ]7 l% T t. Z - }
) n) T: S+ o3 K5 j3 ^7 A- H) G4 s+ }7 v - : P" V8 E3 I% A# i9 M; C
- enc() {: ?+ f7 G0 s- h
- echo -n "$1" | urlencode2 f( ?8 ]; ^* S/ F1 c' F
- }
6 h U: z9 F: n9 {% X9 Z/ b% J
0 L5 q* {! f' r; o" ?- send_request() {9 [9 H# k# M8 A
- local args="AccessKeyId=$aliddnsipv6_ak&Action=$1&Format=json&$2&Version=2015-01-09"1 o; y9 X4 C: n7 F1 N4 [
- local hash=$(echo -n "GET&%2F&$(enc "$args")" | openssl dgst -sha1 -hmac "$aliddnsipv6_sk&" -binary | openssl base64)
6 i/ [+ P. l+ h0 \ - curl -s "http://alidns.aliyuncs.com/?$args&Signature=$(enc "$hash")"
" l5 O* b# Q( z4 P - }2 O+ ?3 z* }0 e, b* }$ d( m8 C% ^) u
3 M1 o# W( W7 u- get_recordid() {
* Q* I9 x. j! u9 M7 ~ - grep -Eo '"RecordId":"[0-9]+"' | cut -d':' -f2 | tr -d '"'
8 L/ }& i; z6 Z' v: X - }
) D4 h3 r2 O+ | - $ L9 G+ w6 g$ `8 h& F4 R* ^9 g" g- t
- query_recordid() {
7 h8 V: N6 e/ @+ j& I - send_request "DescribeSubDomainRecords" "SignatureMethod=HMAC-SHA1&SignatureNonce=$timestamp&SignatureVersion=1.0&SubDomain=$aliddnsipv6_name&Timestamp=$timestamp&Type=AAAA"
, d, u) K, N- s+ Y - }
6 z4 P% i9 {3 F0 p% W. S. V
% `7 S/ S) W/ h- update_record() {& _* h; o9 o# C( [! G
- 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)"
* S4 r2 G" |7 H& v% e - }
% }' r+ B1 J7 K, ]
" s8 m8 Z# E% s( r. E5 a/ H; [+ T- add_record() {
: j7 n, E0 }9 w2 F8 C% J; T - 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)"5 u! W5 E6 l7 Q. ]/ B. [& N
- }
! O# f+ G" t2 a8 n6 j% _ - 2 \8 Z* D2 P" g' x
- #add support */%2A and @/%40 record2 L1 ~" _- Z& g, E
- ) |( k& x8 {* |; ]0 u1 r
; `1 U% L) r- ?" | _- if [ "$aliddnsipv6_record_id" = "" ]* j, Y# E8 r3 W
- then Y$ i U& J( @0 u7 i6 j
- aliddnsipv6_record_id=`query_recordid | get_recordid`9 P5 A b% D9 @4 c
- #echo '-----------------' $aliddnsipv6_record_id
% n0 o" Z- Y. Y4 [, R3 k - fi# i( J& u8 d! [ v) r
- if [ "$aliddnsipv6_record_id" = "" ]
* |+ m8 y$ x5 ^, S5 @0 S7 M - then% a1 I1 A" s6 j5 a
- aliddnsipv6_record_id=`add_record | get_recordid`
) J$ ~' _1 X3 l) k - echo "added record $aliddnsipv6_record_id"" q* ^$ h/ b! B% D" Q7 X4 F
- else2 ]" t) Q+ t5 F/ {$ {/ }
- update_record $aliddnsipv6_record_id9 K+ K4 s c M0 B9 _% u7 d+ L
- echo "updated record $aliddnsipv6_record_id"0 P5 h6 V9 D2 v7 d4 F2 y
- fi
+ ~* U: v7 X. R4 A" n, Y - - \5 @8 Q' O! m, i0 T- v' [, S
复制代码
2 l' V+ d& M0 P( ^! L3 f; x/ h( p, \1 X, q) W' w& Y' w# @
1 q' \4 F1 A2 x
|
|