#!/usr/bin/perl use 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)=@_; my $UA = LWP::UserAgent->new; $UA->default_header( ‘User-Agent‘ => ‘TEST DNS Client/1.0.0 (user@qq.com)‘ ); 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)=@_; my $UA = LWP::UserAgent->new; $UA->default_header( ‘User-Agent‘ => ‘TEST DNS Client/1.0.0 (user@qq.com)‘ ); 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
原文地址:http://zhaolin.blog.51cto.com/9397923/1586357