gtalk自动检测bot0.01

原理:

因为google的 gtalk采用了xmpp协议,因此用开源的实现方案轻松无比,任何jabber的客户端经小改之

都可以与GTalk互通,此段代码用的条件

perl 5.6.0及以上

Net:XMPP

Net:Ping

# !/usr/bin/perl -w
use  strict;
use  Net :: XMPP;
use  Net :: Ping;
# ##########################################
#use Net::Ping mod check the remote machie
#is alive or not!
#sub ping
############################################

sub  ping{
open  END ,   " >/tmp/bot/ping_end_gtalk.txt "  or  die   " cann't open file: $! " ;
my   @ip   =  qw{x . x . x .. 30
           x
. x . x . x . 33
           x
. x . x . x . 34
           x
. x . x . x . 35
           x
. x . x . x . 36
           x
. x . x . x .. 39
           };
my   $host ;
my   $check   =  Net :: Ping -> new();
foreach   $host ( @ip ){
 
if  ( $check -> ping( $host )) {
        
print  END  " $host is alive. " ;
 }
 
else  {
        
print  END  " WARNING!!! $host is unreachable. " ;
 }
}
$check -> close ();
close  END;
}
& ping;



# #########################################
#gtalk send ping_file to x5ywsir
########################################

my   $username   =   " ark119 " ;
my   $password   =   " xxxxxxxxx " ;

my   $body ;
my   $to   =   " x5ywsir " ;
my   $resource   =   " PerlBot " ;
# # End of configuration

#------------------------------------

# Google Talk & Jabber parameters :


my   $hostname   =   ' talk.google.com ' ;
my   $port   =   5222 ;
my   $componentname   =   ' gmail.com ' ;
my   $connectiontype   =   ' tcpip ' ;
my   $tls   =   1 ;

# ------------------------------------

my   $Connection   =  new Net :: XMPP :: Client();

#  Connect to talk.google.com
my   $status   =   $Connection -> Connect (
       hostname 
=>   $hostname ,  port  =>   $port ,
       componentname 
=>   $componentname ,
       connectiontype 
=>   $connectiontype ,  tls  =>   $tls );

if  ( ! ( defined ( $status ))) {
   
print   " ERROR:  XMPP connection failed. " ;
   
print   "         ($!) " ;
   
exit ( 0 );
}

#  Change hostname
my   $sid   =   $Connection -> {SESSION} -> {id};
$Connection -> {STREAM} -> {SIDS} -> { $sid } -> {hostname}  =   $componentname ;

#  Authenticate
my   @result   =   $Connection -> AuthSend(
       username 
=>   $username ,  password  =>   $password ,
       resource 
=>   $resource );

if  ( $result [ 0 ] ne  " ok " ) {
   
print   " ERROR: Authorization failed: $result[0] - $result[1] " ;
   
exit ( 0 );
}

#  Change hostname
my   $sid   =   $Connection -> {SESSION} -> {id};
$Connection -> {STREAM} -> {SIDS} -> { $sid } -> {hostname}  =   $componentname ;

#  Authenticate
my   @result   =   $Connection -> AuthSend(
       username 
=>   $username ,  password  =>   $password ,
       resource 
=>   $resource );

if  ( $result [ 0 ] ne  " ok " ) {
   
print   " ERROR: Authorization failed: $result[0] - $result[1] " ;
   
exit ( 0 );
}

#  Send message
open  PING_FILE ,   " /tmp/bot/ping_end_gtalk.txt " ;
while  ( < PING_FILE > ){
print   $body = $_ ;
$Connection -> MessageSend(
       to 
=>   " $to@$componentname " ,  body  =>   $body ,
       resource 
=>   $resource );
sleep   5 ;
}
close  PING_FILE;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值