[SR-Users] SIP Ping utility with kamailio

JR Richardson jmr.richardson at gmail.com
Fri Oct 15 18:34:55 CEST 2010


On Fri, Oct 15, 2010 at 10:50 AM, Fred Posner <fred at teamforrest.com> wrote:
> On Oct 15, 2010, at 11:42 AM, JR Richardson wrote:
>
>> On Fri, Oct 15, 2010 at 10:22 AM, Fred Posner <fred at teamforrest.com> wrote:
>>> 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
>>
>> Thanks Fred, this works fine, I like the response, you get more info
>> than the 'kamctl ping".
>>
>> I'm looking more for a utility that I can run in the background and
>> graph latency, that gives me specific time value so I can dump into
>> MRTG.
>>
>> Any ideas?
>>
>> JR
>>
>> --
>> JR Richardson
>> Engineering for the Masses
>
> Give this one a try... I think it's the text version of the pdf you were hoping for:
>
> http://flylib.com/books/en/3.439.1.97/1/
>
> ---fred
> http://qxork.com

Good find, that's what I needed, it reports back the latency.  You
have to strip out the leading tabs from the cut and past for the
script to work.  I looked all over for that in text, you must have
super-google.

Thanks a bunch, have a great weekend.

JR
h--
JR Richardson
Engineering for the Masses



More information about the sr-users mailing list