Re: [asterisk-users] Script to automatically update externip. Useful for a host with dynamic public IP

2012-02-06 Thread Klaverstyn, David C
To me it would be simpler to use externhost instead of externip and then use a 
dynamic DNS service.  It has worked flawlessly for me for many years.

Regards
David.


-Original Message-
From: asterisk-users-boun...@lists.digium.com 
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Raj Mathur (??? 
?)
Sent: Tuesday, 7 February 2012 1:19 PM
To: asterisk-users@lists.digium.com
Subject: Re: [asterisk-users] Script to automatically update externip. Useful 
for a host with dynamic public IP

On Monday 06 Feb 2012, John Cahill wrote:
> logger -s "checksetexternip.sh: External IP address 
> has changed, changing /etc/asterisk/sip_general_custom.conf" grep -v 
> "externip" /etc/asterisk/sip_general_custom.conf > 
> /etc/asterisk/sip_general_custom.conf.tmp echo "externip=$EXTERNIP"
> >> /etc/asterisk/sip_general_custom.conf.tmp cp
> /etc/asterisk/sip_general_custom.conf.tmp
> /etc/asterisk/sip_general_custom.conf rm 
> /etc/asterisk/sip_general_custom.conf.tmp

You could also do something like:

  sed -i -e "s/^externip *=.*/externip = $EXTERNIP/"
/etc/asterisk/sip.conf

Apologies for the wrapped code.

Regards,

-- Raj
-- 
Raj Mathur  || r...@kandalaya.org   || GPG:
http://otheronepercent.blogspot.com || http://kandalaya.org || CC68
It is the mind that moves   || http://schizoid.in   || D17F

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to 
Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Script to automatically update externip. Useful for a host with dynamic public IP

2012-02-06 Thread Raj Mathur (राज माथुर)
On Monday 06 Feb 2012, John Cahill wrote:
> logger -s "checksetexternip.sh: External IP address
> has changed, changing /etc/asterisk/sip_general_custom.conf" grep -v
> "externip" /etc/asterisk/sip_general_custom.conf >
> /etc/asterisk/sip_general_custom.conf.tmp echo "externip=$EXTERNIP"
> >> /etc/asterisk/sip_general_custom.conf.tmp cp
> /etc/asterisk/sip_general_custom.conf.tmp
> /etc/asterisk/sip_general_custom.conf rm
> /etc/asterisk/sip_general_custom.conf.tmp

You could also do something like:

  sed -i -e "s/^externip *=.*/externip = $EXTERNIP/"
/etc/asterisk/sip.conf

Apologies for the wrapped code.

Regards,

-- Raj
-- 
Raj Mathur  || r...@kandalaya.org   || GPG:
http://otheronepercent.blogspot.com || http://kandalaya.org || CC68
It is the mind that moves   || http://schizoid.in   || D17F

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Script to automatically update externip. Useful for a host with dynamic public IP

2012-02-06 Thread John Cahill
Note: You'll probably have to change /etc/asterisk/sip_general_custom.conf to 
/etc/asterisk/sip.conf in the script depending on your set-up.


- Original Message -
From: "John Cahill" 
To: "Asterisk Users Mailing" 
Sent: Monday, 6 February, 2012 3:31:23 PM
Subject: [asterisk-users] Script to automatically update externip. Useful for a 
host with dynamic public IP

#!/bin/bash
# checksetexternip.sh
# Author: John Cahill em...@johncahill.net
# Licence: GPL v3
# Description: script that queries checkip.dyndns.com to find the
server's external IP address. Updates asterisk's externip value and does
a sip reload if necessary.
# Last modified 06/02/2012

is_ip(){

input=$1
octet1=$(echo $input | cut -d "." -f1)
octet2=$(echo $input | cut -d "." -f2)
octet3=$(echo $input | cut -d "." -f3)
octet4=$(echo $input | cut -d "." -f4)
stat=1

if [[ $input =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] && [
$octet1 -le 255 ] && [ $octet2 -le 255 ] && [ $octet3 -le 255 ] && [
$octet4 -le 255 ];
then stat=0
fi

return $stat

}

EXTERNIP=`wget -qO- checkip.dyndns.com | awk '{print $6}'| cut -d"<"
-f1` is_ip $EXTERNIP
if [ $? -ne 0 ]
then logger -s "checksetexternip.sh: External IP address invalid or
unavailable, exiting."
exit 1
fi

OLDEXTERNIP=`grep externip /etc/asterisk/sip_general_custom.conf | cut
-d"=" -f2`
if [ "$EXTERNIP" = "$OLDEXTERNIP" ]
then logger -s "checksetexternip.sh: External IP address is the same,
nothing to do exiting."
exit 0
else logger -s "checksetexternip.sh: External IP address has changed,
changing /etc/asterisk/sip_general_custom.conf"
grep -v "externip" /etc/asterisk/sip_general_custom.conf >
/etc/asterisk/sip_general_custom.conf.tmp echo "externip=$EXTERNIP" >>
/etc/asterisk/sip_general_custom.conf.tmp cp
/etc/asterisk/sip_general_custom.conf.tmp
/etc/asterisk/sip_general_custom.conf rm
/etc/asterisk/sip_general_custom.conf.tmp logger -s "Doing asterisk -rx
"sip reload""
asterisk -rx "sip reload"
fi

John Cahill

Systems Engineer

Services for Asterisk
Data Messaging & Communications Ltd
Fourth Floor
22 Lever St
Manchester M1 1EA

Email: j...@dmcip.com
Telephone: 0800 862 0181
Fax: 0161 850 0126
jabber: gnuj...@jabber.org




--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users

-- 
John Cahill 

Systems Engineer 

Services for Asterisk 
Data Messaging & Communications Ltd 
Fourth Floor 
22 Lever St 
Manchester 
M1 1EA 

Email: j...@dmcip.com 
Telephone: 0800 862 0181 
Fax: 0161 850 0126 
jabber: gnuj...@jabber.org 




--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


[asterisk-users] Script to automatically update externip. Useful for a host with dynamic public IP

2012-02-06 Thread John Cahill
#!/bin/bash
# checksetexternip.sh
# Author: John Cahill em...@johncahill.net
# Licence: GPL v3
# Description: script that queries checkip.dyndns.com to find the server's 
external IP address. Updates asterisk's externip value and does a sip reload if 
necessary.
# Last modified 06/02/2012

is_ip(){

input=$1
octet1=$(echo $input | cut -d "." -f1)
octet2=$(echo $input | cut -d "." -f2)
octet3=$(echo $input | cut -d "." -f3)
octet4=$(echo $input | cut -d "." -f4)
stat=1

if [[ $input =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] && [ 
$octet1 -le 255 ] && [ $octet2 -le 255 ] && [ $octet3 -le 255 ] && [ $octet4 
-le 255 ];
  then
stat=0
fi

return  $stat

}

EXTERNIP=`wget -qO- checkip.dyndns.com | awk '{print $6}'| cut -d"<" -f1`
is_ip $EXTERNIP
if [ $? -ne 0 ]
then
logger -s "checksetexternip.sh: External IP address invalid or 
unavailable, exiting."
exit 1
fi

OLDEXTERNIP=`grep externip /etc/asterisk/sip_general_custom.conf | cut -d"=" 
-f2`
if [ "$EXTERNIP" = "$OLDEXTERNIP" ]
then
logger -s "checksetexternip.sh: External IP address is the 
same, nothing to do exiting."
exit 0
else
logger -s "checksetexternip.sh: External IP address has 
changed, changing /etc/asterisk/sip_general_custom.conf"
grep -v "externip" /etc/asterisk/sip_general_custom.conf > 
/etc/asterisk/sip_general_custom.conf.tmp
echo "externip=$EXTERNIP" >> 
/etc/asterisk/sip_general_custom.conf.tmp
cp /etc/asterisk/sip_general_custom.conf.tmp 
/etc/asterisk/sip_general_custom.conf
rm /etc/asterisk/sip_general_custom.conf.tmp
logger -s "Doing asterisk -rx "sip reload""
asterisk -rx "sip reload"
fi

John Cahill 

Systems Engineer 

Services for Asterisk 
Data Messaging & Communications Ltd 
Fourth Floor 
22 Lever St 
Manchester 
M1 1EA 

Email: j...@dmcip.com 
Telephone: 0800 862 0181 
Fax: 0161 850 0126 
jabber: gnuj...@jabber.org 




--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users