Sunday, August 19, 2007

Getting DNS SRV Records for voip through PHP

It is important for the internet service to automatically locate the services at the moment. Just use this code to get the voip protocols service records from the DNS servers.

#!/usr/bin/php
< ?php


$domain = "pulver.com";

$voipprotocol = array("sip","iax");
$transportproto = array("udp","tcp");

foreach($voipprotocol as $voipprot)
{
foreach($transportproto as $trprot)
{
$voipdomain = "_" . $voipprot . "._" . $trprot . "." . $domain;
echo "Searching $voipdomain\n";
$rootinfo = dns_get_record($voipdomain,DNS_ALL, $nsinfo, $addinfo);
//print_r($rootinfo);
foreach($rootinfo as $srootinfo)
echo strtoupper($voipprot) . " " . strtoupper($trprot) . " HOST: " .
$srootinfo['target'] . ":" . $srootinfo['port'] . "\n";
}
}

?>

You can download using svn with the following command,

svn co http://codeoftheday.googlecode.com/svn/trunk/18Aug2007

Do Let me know if there are any improvements done, will keep updated.

Enjoy.

If you want to get this done under C, you can look into the ruli library.

Ruli - DNS SRV Resolver

No comments: