Les Forums

Les Forums

Les forums sont fermés. Ils restent présent pour consultation et archivage.
Vous pouvez désormais poser vos questions directement dans les commentaires en bas de chaque page du site.
Alors n'hésitez pas à participer

Problème avec sip_ping.pl

Bonjour à tous,

J'essaye de faire fonctionner le script en perl (sip_ping.pl) sur mon mac osx lion et cela ne veux pas fonctionner. je joins le script au cas où:
[code:1:94088fd797]
#!/usr/bin/perl
use IO::Socket;
use POSIX 'strftime';
use Time::HiRes qw(gettimeofday tv_interval);
use Getopt::Long;
use strict;

my $USAGE = "Usage: sip_ping.pl [-v] [-t] [-s <src_host>] [-p <src_port] <hostname>";
my $RECV_TIMEOUT = 5; # how long in seconds to wait for a response

my $sock = IO::Socket::INET->new(Proto => 'udp',
LocalPort=>'6655',
ReuseAddr=>1)
or die "Could not make socket: $@";

# options
my ($verbose, $host, $my_ip, $my_port, $time);
GetOptions("verbose|v" => $verbose,
"source-ip|s=s" => $my_ip,
"source-port|p=n"=> $my_port,
"time|t" => $time) or die "Invalid options:\n\n$USAGE\n";

# figure out who to ping
my $host = shift(@ARGV) or die $USAGE;
my $dst_addr = inet_aton($host) or die "Could not find host: $host";
my $dst_ip = inet_ntoa($dst_addr);
my $portaddr = sockaddr_in(5060, $dst_addr);

# figure out who we are
$my_ip = "127.0.0.1" unless defined($my_ip);
$my_port = "6655" unless defined($my_port);

# callid is just 32 random hex chars
my $callid = ""; $callid .= ('0'..'9', "a".."f")[int(rand(16))] for 1 .. 32;
# today's date
my $date = strftime('%a, %e %B %Y %I:%M:%S %Z',localtime());
# branch id - see rfc3261 for more info, using time() for uniqueness
my $branch="z9hG4bK" . time();

my $packet = qq(OPTIONS sip:$dst_ip SIP/2.0
Via: SIP/2.0/UDP $my_ip:$my_port;branch=$branch
From: <sip:ping\@$my_ip>
To: <sip:$host>
Contact: <sip:ping\@$my_ip>
Call-ID: $callid\@$my_ip
CSeq: 102 OPTIONS
User-Agent: sip_ping.pl
Date: $date
Allow: ACK, CANCEL
Content-Length: 0
);

# send the packet
print "Sending: \n\n$packet\n" if $verbose;
send($sock, $packet, 0, $portaddr) == length($packet)
or die "cannot send to $host: $!";
my $send_time = [gettimeofday()]; # start the stopwatch
my $elapsed;

# get the response
eval
{
local $SIG{ALRM} = sub { die "alarm time out" };
alarm $RECV_TIMEOUT;
$portaddr = recv($sock, $packet, 1500, 0) or die "couldn't receive: $!";
$elapsed = tv_interval($send_time); # stop the stopwatch
alarm 0;
1;
} or die($@);

# print our output
if ($verbose) {
printf("After (\%0.2f ms), host said: \n\n\%s\n", $elapsed*1000,
$packet);
}
elsif ($time) {
printf("%0.2f\n", $elapsed*1000);
}
else {
print("$host is alive\n");
}
[/code:1:94088fd797]

J'ai fait l'installation HiRes et tout semble être Ok.

Quand je lance le script, j'obtiens les erreurs suivantes:
sudo ./sip_ping.pl keyyo.net
Password:
./sip_ping.pl: line 2: use: command not found
./sip_ping.pl: line 3: use: command not found
./sip_ping.pl: line 4: syntax error near unexpected token `('
./sip_ping.pl: line 4: ` use Time::HiRes qw(gettimeofday tv_interval);'

J'ai aussi réinstallé perl depuis les binaires d'activeperl.

Merci de votre aide.