如何访问具有动态ip的Linux服务器

通用的方法可以采用花生壳(不过不推荐这些国内域名注册商,这些注册商随意及可以停止解析你的域名而不讲法律,到时你想哭也来不急。),如果觉得麻烦,不妨用下面这个脚本,然后用crontab让它每个10分钟执行一次,如果ip发生变化了,便向你指定的邮箱发送一封包含更新了的ip的邮件。

ipsender

----------------------------------------------

#!/usr/bin/perl

use LWP::Simple;
use strict;

my $pub_ip_file = '/etc/ipsender/mypubip';

my $old_pub_ip = `cat $pub_ip_file`;
chomp($old_pub_ip);

my $new_pub_ip =  get('http://whatismyip.org');
chomp($new_pub_ip);

if($new_pub_ip ne "" && $new_pub_ip ne $old_pub_ip)
{
    open(IPFILE, ">$pub_ip_file") || die "cannot open $pub_ip_file: $!";
    print IPFILE $new_pub_ip;
    close(IPFILE);

my $sendmail = "/usr/sbin/sendmail -t";
    my $sendto = 'To: your@mailbox.com';
    my $subject = 'Subject: pubIP@HOME';

open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
    print SENDMAIL $sendto."/n";
    print SENDMAIL $subject."/n";
    print SENDMAIL "Content-type: text/html/n/n";
    print SENDMAIL "Hi, the public ip at home is changed to $new_pub_ip.";
    close(SENDMAIL);

system("logger /"public ip updated/"");
}
else
{
    system("logger /"public ip unchanged/"");
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pppwz.html