{"id":487958,"date":"2021-05-12T14:24:54","date_gmt":"2021-05-12T06:24:54","guid":{"rendered":"http:\/\/4563.org\/?p=487958"},"modified":"2021-05-12T14:24:54","modified_gmt":"2021-05-12T06:24:54","slug":"%e3%80%90%e6%95%99%e7%a8%8b%e3%80%91%e6%a0%91%e8%8e%93%e6%b4%be%e8%87%aa%e5%8a%a8ddns%e6%9b%b4%e6%96%b0-dnspod","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=487958","title":{"rendered":"\u3010\u6559\u7a0b\u3011\u6811\u8393\u6d3e\u81ea\u52a8DDNS\u66f4\u65b0\/dnspod"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>imes<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u3010\u6559\u7a0b\u3011\u6811\u8393\u6d3e\u81ea\u52a8DDNS\u66f4\u65b0\/dnspod<\/h3>\n<p>  \t\t\u624b\u5934\u4e0a\u7684\u6811\u8393\u6d3e4\u901a\u8fc7WIFI\u8fde\u63a5\u7f51\u7edc\uff0c\u56e0\u4e3a\u662fDHCP\u5206\u914d\u4e00\u4e2a\u516c\u7f51IP\uff0c\u6240\u4ee5\u60f3\u76f4\u63a5\u89e3\u6790\u5230\u56fa\u5b9a\u57df\u540d\u4e0a\uff0c\u907f\u514d\u6bcf\u6b21\u94fe\u63a5\u7684\u65f6\u5019\u90fd\u8981\u624b\u52a8\u53bb\u770b\u5206\u914d\u7684IP\u3002 \u6b64\u5904\u4f7f\u7528\u7684\u662fdnspod\u5bb6\u7684\u670d\u52a1\uff0c\u53ef\u4ee5\u5b9e\u73b0\u79d2\u7ea7\u89e3\u6790\u3002\u7a0b\u5e8f\u662fpython3\u5199\u7684\uff0c\u4f7f\u7528crontab\u7684@reboot\u529f\u80fd\uff08\u5982\u4e0b\uff0c\u6ce8\u610fpath\u8def\u5f84\uff09\u5b9e\u73b0\u5f00\u673a\u542f\u52a8\u540e\u83b7\u53d6IP\u5e76\u81ea\u52a8\u4e0a\u62a5\u3002\u4e3a\u4e86\u65b9\u4fbf\u67e5\u770b\u548c\u8bb0\u5f55\uff0c\u4e5f\u6dfb\u52a0\u4e86\u5c06IP\u63a8\u9001\u5230telegram\u7684\u529f\u80fd\uff08\u81ea\u5efatelegram\u673a\u5668\u4eba\u7684\u6559\u7a0b\uff0chttps:\/\/pa.ci\/119.html\uff09\u3002\u539f\u59cb\u94fe\u63a5https:\/\/pa.ci\/136.html<\/p>\n<p>  @reboot \/usr\/bin\/python3 \/path\/AutoDNS.py<\/p>\n<p>  Python3\u811a\u672c\u5982\u4e0b\uff0c\u9700\u8981\u7533\u8bf7dnspod\u7684login_token\u624d\u80fd\u4f7f\u7528api\uff0c\u6b65\u9aa4\u53c2\u8003\u5b98\u65b9\u6559\u7a0b https:\/\/docs.dnspod.cn\/account\/5f2d466de8320f1a740d9ff3\/ \u3002\u6ce8\u610f\uff01\u6b64token\u53ea\u4f1a\u51fa\u73b0\u4e00\u6b21\uff0c\u4e00\u5b9a\u8981\u590d\u5236\u4e0b\u6765\u4fdd\u5b58\u597d\uff0c\u5e76\u786e\u4fdd\u4e0d\u4f1a\u6cc4\u9732\u3002\u5047\u8bbe\u5df2\u7ecf\u5728dnspod\u91cc\u9762\u89e3\u6790\u8fc7\u4e86raspi.domain.com\uff0c\u5e76\u4e14\u901a\u8fc7curl &#8216;https:\/\/dnsapi.cn\/Domain.List&#8217; -d &#8216;login_token=&lt;login_token&gt;&amp;format=json&#8217;\u83b7\u53d6\u4e86domain_id\uff0c\u901a\u8fc7curl &#8216;https:\/\/dnsapi.cn\/Record.List&#8217; -d &#8216;login_token=&lt;login_token&gt;&amp;format=json&amp;domain_id=&lt;domain_id&gt;&#8217;\u83b7\u53d6\u4e86raspi.domain.com\u7684domain_id\u3002<\/p>\n<p>  import requests<br \/>  import netifaces<br \/>  import telebot<br \/>  import time<br \/>  import sys<\/p>\n<p>  # \u7b49\u5f8510\u79d2\u949f\u4ee5\u4fbf\u7cfb\u7edf\u6709\u8db3\u591f\u7684\u65f6\u95f4\u4ece\u8def\u7531\u5668\u83b7\u53d6ip\u5730\u5740\u3002sleep\u88abloc\u7684\u9632\u706b\u5899\u62e6\u622a\u4e86\uff0c\u9700\u8981\u7684\u8bdd\uff0c\u81ea\u5df1\u5220\u7a7a\u683c\u3002<br \/>  time.s l e e p(10)<\/p>\n<p>  # \u6839\u636ednspod\u7684api\u6807\u51c6\uff0c\u9700\u8981\u6dfb\u52a0User-Agent\u624d\u80fd\u4fdd\u8bc1\u4e0d\u4f1a\u88ab\u5c01\u53f7\uff0c\u683c\u5f0f\u4e3a:\u7a0b\u5e8f\u540d\u79f0\/\u7248\u672c\u53f7 (\u90ae\u4ef6\u5730\u5740)<br \/>  headers \uff1d {&#8216;User-Agent&#8217;: &#8216;RasPi Auto DDNS\/1.0.0 (email@domain.com)&#8217;}<\/p>\n<p>  # \u4f7f\u7528netifaces\u83b7\u53d6wifi\u88ab\u5206\u914d\u7684IP\uff0c\u5982\u679c\u662f\u7f51\u7ebf\u5219wlan0\u53d8\u6210eth0\uff0c\u5982\u679c\u62ff\u4e0d\u5230IP\u5219\u9000\u51fa\u7a0b\u5e8f<br \/>  try:<br \/>  &nbsp; &nbsp; wlan_ip \uff1d netifaces.ifaddresses(&#8216;wlan0&#8217;)[&#8216;addr&#8217;]<br \/>  except:<br \/>  &nbsp; &nbsp; sys.exit(0)<\/p>\n<p>  # \u4ecednspod\u91cc\u5f97\u5230\u4e0a\u6b21\u7684IP\uff0c\u9700\u8981\u5df2\u7ecf\u89e3\u6790\u8fc7\u6b21\u7ea7\u57df\u540d\uff0c\u4ee5raspi.domain.com\u4e3a\u4f8b\u3002<br \/>  url_list \uff1d &#8216;https:\/\/dnsapi.cn\/Record.List&#8217;<br \/>  data_list \uff1d {<br \/>  &nbsp; &nbsp; &#8216;login_token&#8217;: &#8216;123456,4aacc7629e9c7gh58b253cby97f43cdc&#8217;,<br \/>  &nbsp; &nbsp; &#8216;format&#8217;: &#8216;json&#8217;,<br \/>  &nbsp; &nbsp; &#8216;domain_id&#8217;: &#8216;12345678&#8217;,<br \/>  &nbsp; &nbsp; &#8216;sub_domain&#8217;: &#8216;raspi&#8217;,<br \/>  &nbsp; &nbsp; &#8216;record_type&#8217;: &#8216;A&#8217;<br \/>  }<\/p>\n<p>  data_dns \uff1d requests.post(url\uff1durl_list, data\uff1ddata_list, headers\uff1dheaders).json()<br \/>  list_ip \uff1d data_dns[&quot;records&quot;][&quot;value&quot;]<br \/>  # \u5bf9\u6bd4\u6b64\u524d\u7684IP\u548c\u73b0\u5728\u83b7\u53d6\u7684IP\u4e00\u81f4\uff0c\u4e0d\u4e00\u81f4\u5219\u66f4\u6539dnspod\u91cc\u9762\u7684\u8bb0\u5f55<br \/>  if wlan_ip !\uff1d list_ip:<br \/>  &nbsp; &nbsp; url_modify \uff1d &#8216;https:\/\/dnsapi.cn\/Record.Modify&#8217;<br \/>  &nbsp; &nbsp; data_modify \uff1d {<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;login_token&#8217;: &#8216;123456,4aacc7629e9c7gh58b253cby97f43cdc&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;format&#8217;: &#8216;json&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;domain_id&#8217;: &#8216;12345678&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;record_id&#8217;: &#8216;123456789&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;sub_domain&#8217;: &#8216;raspi&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;value&#8217;: wlan_ip,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;record_type&#8217;: &#8216;A&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&#8216;record_line&#8217;: &#8216;u9ED8u8BA4&#8217;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; response_modify \uff1d requests.post(url\uff1durl_modify, data\uff1ddata_modify, headers\uff1dheaders)<br \/>  &nbsp; &nbsp; # \u5c06\u4fe1\u606f\u63a8\u9001\u5230telegram\u4e0a\u4ee5\u4fbf\u67e5\u770b\u8bb0\u5f55\u3002\u5982\u679c\u4e0d\u9700\u8981\uff0c\u53ef\u4ee5\u4ece\u6b64\u5904\u5220\u9664\u5269\u4e0b\u7684\u6240\u6709\u4ee3\u7801\u3002<br \/>  &nbsp; &nbsp; TOKEN \uff1d &#8216;1689581149:AAGYVVjEHsaNjsnT8eQpWyshwr2o4PqU7u8&#8217;<br \/>  &nbsp; &nbsp; tb \uff1d telebot.TeleBot(TOKEN) text \uff1d &quot;The DNS ip is: &quot; + list_ip + &quot; The IP of RasPi is: &quot; + wlan_ip<br \/>  &nbsp; &nbsp; tb.send_message(387980691, text)<br \/>  else:<br \/>  &nbsp; &nbsp; # \u5c06\u4fe1\u606f\u63a8\u9001\u5230telegram\u4e0a\u4ee5\u4fbf\u67e5\u770b\u8bb0\u5f55\u3002\u53ef\u4ee5\u5220\u6389\u4e0d\u8981\uff0c\u5982\u679c\u9700\u8981\u53ef\u4ee5\u53c2\u8003\u7535\u62a5\u673a\u5668\u4eba\u90a3\u91cc\u7684\u6559\u7a0b\u3002<br \/>  &nbsp; &nbsp; TOKEN \uff1d &#8216;1689581149:AAGYVVjEHsaNjsnT8eQpWyshwr2o4PqU7u8&#8217;<br \/>  &nbsp; &nbsp; tb \uff1d telebot.TeleBot(TOKEN) text \uff1d &quot;The IP of RasPi does not change: &quot; + wlan_ip<br \/>  &nbsp; &nbsp; tb.send_message(387980691, text)  \t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>myhost<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\thttps:\/\/github.com\/jeessy2\/ddns-go<\/p>\n<p>  \u8fd9\u4e2a\u4e5f\u4e0d\u9519\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>imes<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tmyhost \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2021-5-12 14:18<br \/>  \u8fd9\u4e2a\u4e5f\u4e0d\u9519<\/p>\n<p> \u8fd9\u4e2a\u6bd4\u6211\u7684\u811a\u672c\u5f3a\u5927\u591a\u4e86yc017t\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>imes \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u3010\u6559\u7a0b\u3011&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/487958"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=487958"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/487958\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=487958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=487958"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=487958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}