如何访问具有动态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: [email protected]';
    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/"");
}

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

你可能感兴趣的:(linux,File,服务器,脚本,System)