邮箱业务往往是公司的重中之重,作为邮箱管理员,必须经常关注己方的出口IP是否被列入黑名单(Spamhaus),如已被列入,会造成终端用户发信被退回,此时须立即从此名单中取出并查明原因。每天上去看也挺麻烦的。写了个简单的小脚本供大家使用。

知识点1: ​​http://www.spamhaus.org/query/ip/1.1.1.1​​ IP换成你公司IP,绿色正常、红色异常。此194的IP说明已被列入CBL(图1)

知识点2: 知道区别就好办了,打开网页源代码,看到如下一行, <FONT color="red" 。那我们只要判断网页中是否含有这行就好(图2)
代码在最下方。每小时自动检核一次,有问题邮件报警。
图1.jpg

图2.jpg

$host.UI.RawUI.WindowTitle = "check_blacklist edit by xing_ji"
for (;;){
Start-Sleep -s 3600
$web1=(Invoke-WebRequest "http://www.spamhaus.org/query/ip/1.1.1.1").content
$web2=(Invoke-WebRequest "http://www.spamhaus.org/query/ip/2.2.2.2").content
if ($web1 -match '<B><FONT color="red">1.1.1.1' )
 {
 $msg1="1.1.1.1 in the blacklist,Pls check!"
 $msg2="2.2.2.2 in the blacklist,Pls check!"
 $ssr="relay.XXX.com"
 $from="[email protected]"
 $to="[email protected]"
 $cc="[email protected]" 
 $body="The ip address is being listed in the spamhaus blacklist.The mail is sent from SHVMMN01,which ip address is 10.101.13.15.For further infomation,please check with http://www.spamhaus.org"
 Send-MailMessage -Subject $msg1 -SmtpServer $ssr -From $from -to $to -cc $cc -Body $body
 }
 elseif ($web2 -match '<B><FONT color="red">2.2.2.2' )
 { Send-MailMessage -Subject $msg2 -SmtpServer $ssr -From $from -to $to -cc $cc -Body $body
 } }