login | register
Wed 19 of Nov, 2008 [22:44 UTC]

voip-info.org

History

IAX2 ping tool

Created by: nezer,Last modification on Thu 13 of Oct, 2005 [15:16 UTC]
  1. !/usr/bin/perl -w
#udp ping tool

use IO::Socket;
$target = shift; #"192.168.0.255";
$target_port = 4569;

socket(PING, PF_INET, SOCK_DGRAM, getprotobyname("udp"));

# Build Packet ... 
# Names from ethereal filter of registration packet

$src_call = "8000"; #8000 most siginificant bit is IAX packet type full ... required for a poke etc...
$dst_call = "0000";
$timestamp = "00000000";
$outbound_seq = "00";
$inbound_seq = "00";
$type = "06"; #IAX_Control
$iax_type = "1e"; #POKE
$msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type;

# Send UDP packet

$ipaddr = inet_aton($target);
$sendto = sockaddr_in($target_port,$ipaddr);

send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n";

# Listen for responses... listen for TIMEOUT seconds and report all responders (works for broadcast pings)

$MAXLEN = 1024;
$TIMEOUT = 5;

eval {
local $SIG{ALRM} = sub { die "alarm time out"; };
alarm $TIMEOUT;

while (1) {
$recvfrom = recv(PING, $msg, $MAXLEN, 0) or die "recv: $!";
($port, $ipaddr) = sockaddr_in($recvfrom);
$respaddr = inet_ntoa($ipaddr);
print "Response from $respaddr : $port\n";
}

};


Comments

Comments Filter
222

333Re: Needs to send an ACK

by john8675309, Tuesday 22 of May, 2007 [16:17:27 UTC]
Here is an example of how to send an ack:

                       $type = "06"; #IAX_Control
                       $iax_type = "04"; #ACK
                        $msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type;
                       send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n";

check this out for more:
http://www.heise.de/netze/rfc/drafts/draft-guy-iax-03.shtml

It is important to note this will kill the current ping process maybe a better way to utilize this would be:

#!/usr/bin/perl -w
#udp ping tool

use IO::Socket;
$target = shift; #"192.168.0.255";
$target_port = 4569;

socket(PING, PF_INET, SOCK_DGRAM, getprotobyname("udp"));

# Build Packet ... 
# Names from ethereal filter of registration packet

$src_call = "8000"; #8000 most siginificant bit is IAX packet type full ... required for a poke etc...
$dst_call = "0000";
$timestamp = "00000000";
$outbound_seq = "00";
$inbound_seq = "00";
$type = "06"; #IAX_Control
$iax_type = "1e"; #POKE
$msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type;

# Send UDP packet

$ipaddr = inet_aton($target);
$sendto = sockaddr_in($target_port,$ipaddr);

send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n";

# Listen for responses... listen for TIMEOUT seconds and report all responders (works for broadcast pings)

$MAXLEN = 1024;
$TIMEOUT = 5;

eval {
local $SIG{ALRM} = sub { die "alarm time out"; };
alarm $TIMEOUT;
$total = 3;
$count = 0;
while ($count < $total) {
  $recvfrom = recv(PING, $msg, $MAXLEN, 0) or die "recv: $!";
  ($port, $ipaddr) = sockaddr_in($recvfrom);
  $respaddr = inet_ntoa($ipaddr);
  print "Response from $respaddr : $port\n";
  $count++;
}

$type = "06"; #IAX_Control
$iax_type = "04"; #ACK
$msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type;
send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n";

};

if ($@) {
       print "Error Timeout waiting for packet from: $target\r\n";
       $type = "06"; #IAX_Control
       $iax_type = "04"; #ACK
       $msg = pack "H24", $src_call . $dst_call . $timestamp . $outbound_seq . $inbound_seq . $type . $iax_type;
       send(PING, $msg, 0, $sendto) == length($msg) or die "cannot send to $target : $target_port : $!\n";
}

222

333Needs to send an ACK

by lschweiss, Thursday 09 of March, 2006 [18:31:37 UTC]
Asterisk really doesn't like this tool.

Once you ping Asterisk with this tool, Asterisk keeps responding looking for an ACK packet in return.

My perl is very rusty. Anyone care to update the this tool to be more friendly?