qns_fengyusong 发表于 2015-12-27 09:41:56

Perl初试

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



#!/usr/bin/perl -w
#       auth:lichmama@cnblogs.com
#       what:send message to phone
#       usage: sms.pl
use strict;
use Socket;
if(scalar @ARGV != 2){
die "Usage: sms.pl \n";
}
my $phone = $ARGV;
my $text = $ARGV;
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);
  
页: [1]
查看完整版本: Perl初试