加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl检测网站首页状态

发布时间:2020-12-16 00:39:06 所属栏目:大数据 来源:网络整理
导读:?perl检测网站首页状态代码,随便写的,一起交流 #!/usr/bin/perl -w? ? use strict;? use LWP::UserAgent;? use Net::SMTP;? use POSIX qw/strftime/;? ? print EOF;? +--------------------------------------+? +----made by Henry He on 2011/03/03----+

?perl检测网站首页状态代码,随便写的,一起交流

#!/usr/bin/perl -w?
?
use strict;?
use LWP::UserAgent;?
use Net::SMTP;?
use POSIX qw/strftime/;?
?
print <<EOF;?
+--------------------------------------+?
+----made by Henry He on 2011/03/03----+?
+--------------------------------------+?
EOF?
?
my @array = ();?
my $count = 0;?
?
open FILE,'<','url.txt' or die "$!n";?
?
while (<FILE>) {?
? ? ? ?chomp;?
? ? ? ?/(S+)/;?
? ? ? ?push @array,$1;?
}?
?
close FILE;?
?
foreach my $url (@array) {?
?
? ? ? ? $count++;?
?
? ? ? ? my $obj = LWP::UserAgent->new(?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? keep_alive=>1,?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? timeout=>60);?
?
? ? ? ? my $req = HTTP::Request->new(GET=>"$url");?
?
? ? ? ? my $res = $obj->request($req);?
?
? ? ? ? if ($res->is_success) {?
? ? ? ? ? ? print $url,"t",$res->status_line,"n";?
? ? ? ? } else {?
? ? ? ? ? ? print "$urltFailed:t","n";?
? ? ? ? ? ? sendemail("$urltFailed:t" . $res->status_line,"n");?
? ? ? ? }?
?
}?
?
my $cur_time = strftime "%Y-%m-%d",localtime;?
?
print "n";?
print <<EOF;?
+-------------------------------------+?
+ ? ? ?Finished check $count urls ? ? +?
+-------------------------------------+?
EOF?
?
printlog("finished check $count urls at $cur_time...n");?
?
sub sendemail {?
? ? my $content = shift;?
? ? #change it for your smtp server?
? ? my $host = 'smtp.163.com';?
? ? #your email account here?
? ? my $mail_from = 'your_email_account';?
? ? #change it what you want to send here?
? ? my $mail_to = 'abc@abc.com';?
? ? #email subject?
? ? my $subject = 'Error Notice';?
?
? ? my $smtp = Net::SMTP->new($host,?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Hello=>'localhost',?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Timeout=>120,?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Debug=>1?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? );?
? ? ?# modify it with your email username and password?
? ? ?$smtp->auth('your_email_username','your_email_password');?
? ? ?$smtp->mail($mail_from);?
? ? ?$smtp->to($mail_to);?
? ? ?$smtp->data();?
? ? ?$smtp->datasend("To: $mail_ton");?
? ? ?$smtp->datasend("From: $mail_fromn");?
? ? ?$smtp->datasend("Subject: $subjectn");?
? ? ?$smtp->datasend("n");?
? ? ?$smtp->datasend("$contentnn");?
? ? ?$smtp->dataend();?
? ? ?$smtp->quit;?
?
}?
?
sub printlog {?
? ? my $str = shift;?
? ? open LOG,'>>','check_url_status.log' or die "$!n";?
? ? print LOG "$str";?
? ? close LOG;?
}?
url.txt
code:
http://www.abc.com?
http://www.test.com?
http://www.xyz.com?
…………………………?
…………………………?
…………………………?
http://www.def.com?
http://www.123.com?
?
本文出自 “BSDerの” 博客,请务必保留此出处http://hellosa.blog.51cto.com/2698675/505781

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读