[SR-Users] SIP Ping utility with kamailio
Fred Posner
fred at teamforrest.com
Fri Oct 15 17:22:57 CEST 2010
Hey JR...
I use this:
#! /usr/bin/perl -w
use IO::Socket;
use POSIX 'strftime';
my ($msg,$remotehost,$callid,$socket,$date,$branch,$localip,$dest);
$remotehost = $ARGV[0]
or die "FAIL \(no host defined\)\n";
if ($ARGV[1]) {
$remoteport = $ARGV[1];
} else {
$remoteport = "5060";
}
if ($ARGV[2]) {
$localip = $ARGV[2];
} else {
$localip = "127.0.0.1";
}
if ($ARGV[2]) {
$dest = $ARGV[3];
} else {
$dest = "ping";
}
$socket = IO::Socket::INET->new (
PeerAddr => $remotehost,
PeerPort => $remoteport,
Proto => 'udp',
) or die "FAIL Could not create socket: $!n";
$callid .= ('0'..'9', "a".."f")[int(rand(16))] for 1 .. 32;
$date = strftime('%a, %e %B %Y %I:%M:%S %Z',localtime());
$branch="z9hG4bk" . time();
my $packet = qq(OPTIONS sip:$remotehost SIP/2.0
Via: SIP/2.0/UDP $localip:$remoteport;branch=$branch
From: <sip:$dest\@$localip>
To: <sip:$remotehost>
Contact: <sip:$dest\@$localip
Call-ID: $callid\@$localip
CSeq: 102 Options
User-Agent: sipcheck.pl
Date: $date
Allow: ACK, CANCEL
Content-Length: 0
);
print $socket $packet;
eval {
local $SIG{ALRM} = sub { die };
alarm 5;
my $sock_addr = recv($socket,$msg,190,0);
alarm 0;
1;
} or die("FAIL\n");
if ($msg) {
print "UP\n";
print "response is $msg\n";
} else {
print "FAIL no msg received\n";
}
close($socket);
---fred
http://qxork.com
On Oct 15, 2010, at 11:14 AM, JR Richardson wrote:
> Hi All,
>
> Can someone point me in the right direction of a command line SIP Ping
> utility or how to invoke from Kamailio? I see there is a sip_ping.pl
> script in voip-hacks, does anyone have copy-paste text version of
> that, all I can find is the PDF?
>
> Thanks.
>
> JR
> --
> JR Richardson
> Engineering for the Masses
>
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
More information about the sr-users
mailing list