[Asterisk-Users] Re: Re: Asterisk and a SPA3000behindNATpeerregistration

Alchaemist info at lnet.com.ar
Thu Sep 22 10:19:36 MST 2005


Hi,

    Lets see... dynamic IP, means mainly two options:

1- PPPoE in the same machine as asterisk
    In that case, you can get the IP locallyin the shell
2- Whatever protocol, in a router
    In that case you must rely in querying your router or an external system 
(like www.myipaddress.com)

    Now, in the confs, you need in sip.conf a line like "#include 
sip_nat.conf"
    Then, in your script you would need something like this php with 
wrappers enabled
    And finally you need to setup the right cron with the script.

CASE 2 - External IP source
  Put the right file path in $ConfFile, and make this script run in your 
cron, often... the interval you setup will be the maximum "SIP trouble time" 
you will have.
  Just in case don't put it with an interval too low, because it might be 
something nasty to do to a website like this.
  Also, if you want to change it for your router webpage, then all you have 
to do, is to update the URL and the regex. If it has password, all you have 
to do is to use an URL like http://user:password@myrouterip/path/to/page
#---------------------------------------------------------------------------------------------
#!/usr/bin/php -q
<?php
  $ConfFile = 'sip_nat.conf';
  $Webpage = file_get_contents('http://www.myipaddress.com');
  $Matches = array();
  preg_match('/<p>.*IP address is\:<a 
href=.about..>\*<\/a>\s*<p><b>(\d+\.\d+\.\d+\.\d+)<\/b>/i',$Webpage,$Matches);
  $IP = @ $Matches[1];
  if ($IP){
   echo "Your IP is: $IP\n";
   if ($FH = fopen($ConfFile,'w')){
    fputs($FH,"externip=$IP\n");
    fclose($FH);
    $Reload = `asterisk -rx \"sip reload\"`;
    echo "Reload Status: $Reload\n";
   }
   else{
    echo "Unable to save file.\nSomething odd is going on, check permissions 
and paths.\n";
   }
  }
  else{
   echo "Unable to detect IP.\nPerhaps you are not connected, the website is 
down, or it changed its HTML.\n";
  }
#---------------------------------------------------------------------------------------------



CASE 1 - Similar to case 2, except that you get the IP from a local command, 
I've seen an SH script that does this work, in this very list, somewhere.
Another difference is that instead of letting the cron regularly run it, you 
can/must run it every time the os detects an IP change/interface reload, 
init.d something, I cannot recall it now. Anyway case 2 will work as well.


    Cheers!

Alchaemist

----- Original Message ----- 
From: "razza" <rjames31 at btopenworld.com>
Newsgroups: gmane.comp.telephony.pbx.asterisk.user
Sent: Thursday, September 22, 2005 5:24 AM
Subject: RE: Re: Asterisk and a SPA3000behindNATpeerregistration


>
> Alchaemist Wrote:
>>Now... if you have dynamic IP in the asterisk... things change....
> because
>>Asterisk must know in sip.conf the external IP.
>>I think I read in this list, that the best (only?) way to get arround,
> is to
>>place a script that detects the external IP when it changes,updates
> sip.conf
>>(preferably another conf like sip_nat.conf that is included into
> sip.conf),
>>and then uses the CLI to reload the sip configuration, you have a
> command I
>>cannot recall right now to only reload that part instead of the whole
> bunch
>>of confs.
>
> The problem is no one has come back with a script which does the job :o(
> The command to reload the sip.conf is -
> asterisk -rx "sip reload"






More information about the asterisk-users mailing list