gtalk自动检测bot0.01
来源:互联网 发布:java正则表达式( 编辑:程序博客网 时间:2024/05/29 13:04
原理:
因为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;
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;
- gtalk自动检测bot0.01
- gtalk
- [gtalk]gtalk机器人
- Gtalk新功能
- 什么是Gtalk
- Gtalk登陆
- gtalk robot
- GTALK机器人
- 自动检测文件
- 车牌自动检测
- 串口自动检测
- 在线版Gtalk:Gtalkr
- 我爱gtalk
- MSN与Gtalk互通!
- GTalk 推出简体中文版
- 安全的 Gtalk
- 用Gaim登录Gtalk
- Splinter(Gtalk)的免费网络电话
- .net2.0 控件 winform Datagridview简介
- 使用 Cypal Studio for GWT 简化 Ajax 开发
- WPF中,Grid与Table的区别(英文)
- Linux查找文件的相关命令说明
- 懂得测试
- gtalk自动检测bot0.01
- Silverlight 学习网站集锦
- UML系列学习之——UML简介
- UML复习系列之二(工具使用)
- c#操作XML
- BPEL definition
- 技术开发频道一周精选2007-8-10
- c#操作XML二
- test2