LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 804|回复: 3

一个动态域名脚本文件

[复制链接]
发表于 2005-2-11 10:07:43 | 显示全部楼层 |阅读模式
最近在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("$usernamepassword");

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);
}
发表于 2005-2-11 11:16:28 | 显示全部楼层
这个脚本是用来更新动态IP地址(因为ADSL的公网IP是不固定的)到它提供的域名解析服务器吧。
把其中的用户 名密码什么的设置成你在网站上设定好的资料。然后执行这个脚本就可以把你的公网IP更新掉。这样其它人通过域名就可以正确访问你的机。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-11 12:29:11 | 显示全部楼层
谢谢这位热心的兄弟!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-11 12:30:09 | 显示全部楼层
大家测试一下,是用p70 16M 2G的配置建的ftp  ftp://lqy.hn.org  用户名和密码都是down
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表