用于ChinaDNS注册过域名,并拥有MyDNS的用户想在BSD或其它*nix系统上实现动态域名指向的代码
代码:
#!/usr/bin/perl # ChinaDNS | ADSL PPP | Dynamic-IP DNS. # File: ./xa-dns # Author: xiean [2003-06-10] # OS: FreeBSD 4.x # PKG: Need for openssl # p5-libwww # p5-IO-Socket-SSL # USAGE: modify /etc/ppp/ppp.linkup, add this line. # [your ppp system]: # iface clear # !bg /path/to/xa-dns MYADDR # # e.g: if you use cmdline 'ppp -ddial -nat pppoe', that's # pppoe: # iface clear # !bg /path/to/xa-dns MYADDR
use strict; use LWP; use HTTP::Request::Common;
# Domain Login Form. # [Domain] = Domain, [Suffix] = .net or .com or [...], [Password] = Domain Password use constant ChinaDNS_Login => 'https://www.paycenter.com.cn/cgi-bin/nEWpAYcENTER/Domain/DomainLogin';
# Get Session, and go to MyDNS page. use constant ChinaDNS_MyDNS => 'http://www.paycenter.com.cn/cgi-bin/udns?Number=1&';
# Get Domain old IP, mystring, mystring2 and post form to modify url. # [hostname] = 'soho.xiean.net' or [...], [oldhostip], [newhostip] = $My_ADSL_IP, [action] = 'modifyhost', # [DomainName] = 'xiean.net', [mystring], [mystring2] use constant MyDNS_Modify => 'http://mydns.chinadns.com/cgi-bin/mydnsinfo.cgi';
my $Domain = 'xiean'; # modify this to your domain's name. my $Suffix = '.net'; # modify this to your domain's suffix. (.com|.net|.org|.com.cn|.....) my $Domain_Key = '********'; # This is your domain's passwd, you can get it from # http://www.chinadns.com member area. e.g: 'a1b2c3d4' my @Host = ('soho.xiean.net'); # Put in you want to modify domain. # e.g: @Host = ('xiean.net', 'test1.xiean.net', 'test1.xiean.net', '.....')
my $My_ADSL_IP = shift;
my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/4.7 [en] (PalmOS)');
# Modify ChinaDNS.com > MyDNS > @Host Dynamic-IP DNS. # Step 1 my $request = POST(ChinaDNS_Login, Content => [ Domain => $Domain, Suffix => $Suffix, Password => $xiean_net_Key], Referer => 'http://www.paycenter.com.cn/');
my $response = $ua->request($request); die $response->message unless $response->is_success;
my $content = $response->content; $content =~ /(Session=\d+)/g; my $SessionID = $1;
# Step 2 my $request = GET(ChinaDNS_MyDNS . $SessionID, Referer => 'http://www.paycenter.com.cn/');
my $response = $ua->request($request); die $response->message unless $response->is_success;
my $content = $response->content; # modify soho\.xiean\.net to you want to modify domain. e.g: xiean\.20cn\.com $content =~ /'soho\.xiean\.net'\,'(\d+\.\d+\.\d+\.\d+)'/g; my $OldIP = $1; $content =~ /\"mystring\" type=\"hidden\" value=\"(\w+)\">/g; my $mystring = $1; $content =~ /\"mystring2\" type=\"hidden\" value=\"(\d+)\">/g; my $mystring2 = $1;
# Step 3 while(my $Host = shift(@Host)) { my $request = POST(MyDNS_Modify, Content => [ hostname => $Host, oldhostip => $OldIP, newhostip => $My_ADSL_IP, action => 'modifyhost', DomainName => $Domain . $Suffix, mystring => $mystring, mystring2 => $mystring2 ], Referer => 'http://www.paycenter.com.cn/');
my $response = $ua->request($request); die $response->message unless $response->is_success; my $content = $response->content; }
1;
|