|
|
最近在http://hn.org里申请了动态域名,但只有一个这样的客户端文件:hammernode.pl
哪位兄弟会使用?谢谢
hammernode.pl
客户端内容如下:
#!/usr/bin/perl -w
# DISCLAIMER: I haven't used hn.org in literally years. If this breaks,
# you get to pick up the pieces. Anyone wanna take this one over?
use strict;
use vars qw($myip $firewall $target $username $password $version);
use vars qw($pass $url $sock @result $result $code);
# YOUR hn.org name and password go here.
$username = "yourname";
$password = "yourpass";
# If you're behind a firewall or HTTP proxy, set this to 1.
# If you're not sure, set it to 1; that's the safer setting anyway.
# If you KNOW you're not behind a firewall or proxy, set to 0.
$firewall = 1;
# Okay, that's all you'll need to configure *here*. You're not done,
# though... You still need to configure this to run automatically, and to
# use the correct IP address. For Linux users with pppd, the easiest way
# to put a line like this in /etc/ppp/ip-up :
#
# /usr/local/sbin/hammernode.pl $4
#
# If that doesn't make much sense, see `man pppd' which details what
# parameters pppd sends to ip-up.
#
# A clever trick for dhcpcd users... put this in your
# /etc/dhcpcd/dhcpcd-eth0.exe file:
#
# source /etc/dhcpc/dhcpcd-eth0.info && /usr/local/sbin/hammernode.pl $IPADDR
#
# (I discovered this was necessary -- my cable modem company puts an
# "invisible" HTTP proxy in between me and the 'net, and my domains were
# being assigned the address of the proxy.
#
# (C)2000-2001 David E. Smith <dave@bureau42.com> and released to the
# public under the terms of the GNU General Public License.
#
# Modified by Daniel Hagan <dhagan@colltech.com> on 4/2001 to use IO::Socket,
# Syslog, and some error checking. Now logs all output to daemon facility.
#
# Other changes made/suggested by Aurelien Beaujean <aure@dagobah.eu.org>
# Sorry, but I can't type the accent over the first "e" in Aurelien.
#
# Update 12 Jan 2002: Gregory Keefe changed the format. It now
# connects to username.dup.hn.org. My account there died a long time
# ago, so I can't test this version, but it should work.
#
# Update 26 Sep 2002: Kamosawa Masao (or perhaps Masao Kamosawa -- some
# Japanese persons American-ize their names when dealing with Americans,
# some don't) fixed a bug with the $firewall handling.
#
###############
use MIME::Base64 ();
use Sys::Syslog qw( EFAULT setlogsock);
use IO::Socket;
# If you don't let syslogd listen on an inet port, uncomment this line.
#
#setlogsock 'unix';
openlog ("hammernode", 'pid', 'daemon');
$myip = shift;
if ($firewall && !$myip) {
syslog ('err', "FATAL: IP required as command line argument when \$firewall is set to true.");
exit(1);
}
$myip = "current address" if !$myip;
$target = "dup.hn.org";
$version = "v0.22pl2";
$pass = MIME::Base64::encode_base64("$username password");
if ($firewall == 1) {
$url = "/vanity/update/?VER=1&IP=$myip" ;
} else {
$url = "/vanity/update/?VER=1" ;
}
syslog ('info', 'Setting domain to %s.', $myip);
$sock = new IO::Socket::INET(
PeerAddr => "$target",
PeerPort => 'http(80)'
);
if (!$sock) {
syslog('err', "FATAL: Connect to $target, port 80, failed: %m");
exit(1);
}
$sock->autoflush(1);
$sock->print("GET $url HTTP/1.0\r\n");
$sock->print("User-Agent: hammenode.pl $version\r\n");
$sock->print("Host: $target\r\n");
$sock->print("Authorization: Basic $pass\r\n\r\n");
# Legacy sleep from v0.21. May be necessary on some slow PC platforms.
# If you are having problems, try uncommenting this first.
#
#sleep 5;
@result = $sock->getlines();
undef $sock; #Close the socket
$result = join '', @result;
$result =~ m/DDNS_Response_Code=(\d+)/i;
$code = $1;
$result =~ m/.*>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})<.*/i;
$myip = $1;
if ($code == 101) {
syslog ('info', "Succeeded in setting domain to $myip.");
exit(0);
} else {
syslog ('notice', "Received DDNS Reponse Code $code, probably failed.");
exit(1);
} |
|