標籤:dnspod dns api 解析 perl
#!/usr/bin/perluse strict;use warnings;use LWP::UserAgent;use JSON;use Encode;my $mail=‘user‘;my $pass=‘pass‘;my $domain_info_url=‘https://dnsapi.cn/Domain.Info‘;my $record_list_url=‘https://dnsapi.cn/Record.List‘;sub get_domain_id {###擷取資料my ($domain)[email protected]_;my $UA = LWP::UserAgent->new;$UA->default_header( ‘User-Agent‘ => ‘TEST DNS Client/1.0.0 ([email protected])‘ );my $response = $UA->post( $domain_info_url, [ ‘login_email‘ => "$mail",‘login_password‘ => "$pass",‘format‘ => ‘json‘,"domain" => "$domain"] );my @string = $response->content;###利用JSON 處理資料my $json_obj;my $json = new JSON;foreach (@string){$json_obj = $json->decode("$_");}return $json_obj->{‘domain‘}->{‘id‘};}sub get_record_list {my ($domain_id,$sub_domain)[email protected]_;my $UA = LWP::UserAgent->new;$UA->default_header( ‘User-Agent‘ => ‘TEST DNS Client/1.0.0 ([email protected])‘ );my $response = $UA->post( $record_list_url, [ ‘login_email‘ => "$mail",‘login_password‘ => "$pass",‘format‘ => ‘json‘,"domain_id" => "$domain_id","sub_domain" => "$sub_domain"] );return $response->content;}my $json_obj;my $json = JSON->new->utf8;foreach (get_record_list(get_domain_id("main_domain.com"),"test")){ $json_obj = $json->decode("$_");}###main_domain.com為主網域名稱,test次層網域my ($cast,@t);for my $item(@{$json_obj->{‘records‘}}){ $cast = $item->{‘ttl‘} . "_" . $item->{‘line‘} . "_" . $item->{‘value‘}; push (@t,$cast);}#####此處可以擷取的值: # "id": "744",# "name": "hot",# "line": "預設",# "type": "A",# "ttl": "60",# "value": "1.1.1.1",# "mx": "0",# "enabled": "1",# "status": "enabled",# "monitor_status": "",# "remark": "",# "updated_on": "2014-07-30 12:38:44",# "use_aqb": "no" foreach (@t){my $re = encode("gb2312",$_); print "$re\n";}
以上是自己寫的一個perl , 剛入門 寫的有點亂。
本文出自 “perling” 部落格,請務必保留此出處http://zhaolin.blog.51cto.com/9397923/1586357
perl利用DNSPOD API擷取網域名稱的各個地區的解析