Last active
August 29, 2015 14:24
-
-
Save vitorbaptista/bcc1ccf628035a642050 to your computer and use it in GitHub Desktop.
Ping IAX2 server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# udp ping tool | |
# http://www.voip-info.org/wiki/index.php?page_id=2654&comments_page=1 | |
use IO::Socket; | |
$target = shift; #"192.168.0.255"; | |
$target_port = shift; # 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\n"; }; | |
alarm $TIMEOUT; | |
recv(PING, $msg, $MAXLEN, 0) or die "recv: $!"; | |
alarm 0; | |
}; | |
$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 ($@) { | |
exit -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment