2010年9月、Yandexは、一般向けにドメイン向けメールの
DNSホスティングを開始
しました。 ユーザーの喜びは際限がなく、トピックには多くの肯定的なコメントが寄せられ、Yandexは善良な企業によって発表されました。
残念ながら、DNSレコードの管理はWebインターフェースを介してのみ提供されていました。 APIは管理用に提供されておらず、まだ登場しておらず、長期間登場しない可能性があります。 この事実により、ダイナミックIPドメインの所有者の多くは、DynDNSによる後者の購入に関連して、優れたfree.editdns.netの無料サービスを有料ベース(カスタムドメイン用)に移行することになります。
奇跡が起こらなかったことを確認した後、この不正を修正するために
Pythonからファイルを選びました...
まず、YandexサービスAPIについて少なくとも何らかの情報を探して、すべてを知っているGoogleに行きました。 最初に出会ったのは、ドメイン用のMail APIの詳細な説明でした。 残念ながら、利用可能な32の機能のうち、DNSホスティングの管理に関連するものは何もなかったので、検索を続けました。 リクエストにpythonマジックワードを追加し、その後cシャープを使用して、Yandexサービスで許可する際のブラウザーの詳細な説明とVBおよびC#のコードの例に関する
Alexei Nemiroの記事に出会いました。
記事を読んで、ブラウザーをシミュレートする必要があることを確認した後、
FireBugと
HTTPアナライザーで武装し
ました 。 承認の複雑さを研究し、DNSホスティングで作業するのにしばらく時間を費やした後、Yandexサービスでの承認が非常に簡単に機能することがわかりました。 許可手順は、
yandexuid cookieで始まります。これは、Yandexサービスにログインしたときに受信されます。
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Copy Source | Copy HTML def initialize (self): connection = httplib .HTTPConnection( 'www.yandex.ru' ) connection.request( 'GET' , '/' ) response = connection.getresponse() cookies = response.getheader( 'set-cookie' , None) response.close() match = re .search( '(?<=yandexuid=)[^;]*' , cookies) self ._yandexuid = match.group( 0 ) print 'yandexuid =' , self ._yandexuid
Cookie yandexuidを受信した後
、ブラウザはログイン、パスワード、タイムスタンプをUNIX形式でPOSTリクエストとともに送信します。 リクエストの形成に問題がなければ、私は長い間タイムスタンプ式にとどまりました:
Copy Source | Copy HTML
- def ログイン (自己):
- content = 'login = {0}&passwd = {1}&timestamp = {2}'
- content = content.format( self ._login、 self ._passwd、 self .timestamp())
- connection = httplib .HTTPConnection( 'passport.yandex.ru' )
- connection.request( 'POST' 、 '/ passport?mode = auth' 、content、{ 'Cookie' : self .getcookies()})
- 応答= connection.getresponse()
- 内容= response.read()
- response.close()
- match = re .search( 'idkey \ "\ s。*' 、content)
- match = re .search( '(\ d \ w *)' 、match.group( 0 ))
- self ._idkey = match.group( 0 )
- print 'idkey =' 、 self ._idkey
「このコンピューターに永続的な認証を設定する」というリクエストに応えて、マジックIDキーを受け取った後、「いいえ」ボタンのクリックをシミュレートするリクエストを作成する必要がありました。
Copy Source | Copy HTML
- def 認証 (自己):
- content = 'filled = yes&timestamp = {0}&idkey = {1}&no =%D0%9D%D0%B5%D1%82'
- content = content.format( self .timestamp()、 self ._idkey)
- connection = httplib .HTTPConnection( 'passport.yandex.ru' )
- connection.request( 'POST' 、 '/ passport?mode = auth' 、content、{ 'Cookie' : self .getcookies()})
- 応答= connection.getresponse()
- cookies = response.getheader( 'set-cookie' 、なし)
- ... cook regexpの解析...
- response.close()
ドメインのメールを操作するために必要なすべてのCookieを手に入れたので、内部AJAX APIを介してDNSレコードエディターの[保存]ボタンのクリックをシミュレートするだけで十分です。
Copy Source | Copy HTML
- def updatedomain (self、ns_record_id):
- content = 'domain = {0}&ns_record_id = {1}&ns_rec_type = A&ns_subdomain =%40&ns_weight =&ns_port =&ns_content = {2}&ns_priority = 1'
- content = content.format( self ._domain、ns_record_id、 self ._externalip)
- connection = httplib .HTTPSConnection( 'pdd.yandex.ru' )
- connection.request( 'POST' 、 '/ajax/ns_simple_record_edit.ajax.xml' 、コンテンツ、\
- { 'Accept' : 'application / json、text / javascript、* / *' 、\
- 'Cookie' : self .getcookies()})
- 応答= connection.getresponse()
- response.close()
前のケースと同様に、この時点でAcceptヘッダーが必要でした。 ただし、これは最も重要ではありません。
ns_record_idを取得するには、ページのHTMLコードをDNSレコードのリストで解析する必要がありました。
Copy Source | Copy HTML
- def domainlist (self):
- connection = httplib .HTTPSConnection( 'pdd.yandex.ru' )
- connection.request( 'GET' 、 '/ domain_ns / {0} /' .format( self ._domain)、なし、\
- { 'Accept' : 'text / html、application / xhtml + xml、application / xml; q = 0.9、* / *; q = 0.8' 、\
- 'Cookie' : self .getcookies()、\
- 'Referer' : 'https://pdd.yandex.ru' })
- 応答= connection.getresponse()
- 内容= response.read()
- block = re .findall( 'item:\ s \' [\ d] + \ '(。+)value = "[\ w \。] +"' 、コンテンツ)
- ブロック内のアイテムの場合:
- match = re .search( '(?<= item:\ s \')[\ d] * ' 、item)
- ns_record_id = match.group( 0 )
- match = re .search( 'ns_subdomain(。+?)value = \ "(。+?)\"' 、item)
- match = re .search( '(?<= value =)\ "。+?\"' 、match.group( 0 ))
- ns_subdomain = match.group( 0 )
- match = re .search( 'ns_rec_type(。+?)value = \ "(。+?)\"' 、item)
- match = re .search( '(?<= value =)\ "。+?\"' 、match.group( 0 ))
- ns_rec_type = match.group( 0 )
- match = re .search( 'ns_content(。+?)value = \ "(。+?)\"' 、item)
- match = re .search( '(?<= value =)\ "。+?\"' 、match.group( 0 ))
- ns_content = match.group( 0 )
- レコード= 'ns_record_id = {0} | ns_subdomain = {1} | ns_rec_type = {2} | ns_content = {3} '
- record.formatの出力(ns_record_id、ns_subdomain、ns_rec_type、ns_content)
- response.close()
これは私の最初のPythonプログラムであったため、httplibと手動のCookie形成に限定しました。 コマンドラインパラメーターを追加し、構成を解析し、このカクテルに外部IPを取得すると、Yandex DNSホスティングのDNSレコードを更新するための簡単なスクリプトが得られました。
ソースコードとサンプル設定をダウンロードします 。