Perl初试

通过接口发送短信的socket小样:

#!/usr/bin/perl -w
#       auth:lichmama@cnblogs.com
#       what:send message to phone
#       usage: sms.pl [phonenumber] [text]

use strict;
use Socket;

if(scalar @ARGV != 2){
    die "Usage: sms.pl [phonenumber] [text]\n";
}

my $phone = $ARGV[0];
my $text = $ARGV[1];

my $sms_host = "xxx.xxx.xxx.xxx";
my $sms_port = 8089;

socket(SOCK, AF_INET, SOCK_STREAM, getprotobyname("tcp")) 
    or die "Error: cannot create socket\n";
connect(SOCK, sockaddr_in($sms_port, inet_aton($sms_host))) 
    or die "Error: cannot connect sms server\n";
send(SOCK, "$phone||$text", 0) 
    or die "Error: an unexpected exception occurred when sending message\n";

close(SOCK);

 

posted @ 2015-03-26 15:05  lichmama  阅读(160)  评论(0编辑  收藏  举报