[asterisk-commits] mvanbaak: trunk r168265 - in /trunk: CHANGES contrib/scripts/sip_nat_settings

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 9 17:04:48 CST 2009


Author: mvanbaak
Date: Fri Jan  9 17:04:46 2009
New Revision: 168265

URL: http://svn.digium.com/view/asterisk?view=rev&rev=168265
Log:
Add a script to find out the correct settings for Asterisk behind NAT

(closes issue #13065)
Reported by: tzafrir
Patches:
      sip_nat_settings uploaded by tzafrir (license 46)
      sip_nat_settings_6 uploaded by mvanbaak (license 7)
Tested by: tzafrir, pabelanger, Dovid and moi

Added:
    trunk/contrib/scripts/sip_nat_settings   (with props)
Modified:
    trunk/CHANGES

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?view=diff&rev=168265&r1=168264&r2=168265
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Fri Jan  9 17:04:46 2009
@@ -114,6 +114,9 @@
    timezones, especially if those daylight savings time ranges vary from your
    machine's native timezone.  See GotoIfTime, ExecIfTime, IFTIME(), and timed
    includes.
+ * The contrib/scripts/ directory now has a script called sip_nat_settings that will
+   give you the correct output for an asterisk box behind nat. It will give you the
+   externhost and localnet settings.
 
 Asterisk Manager Interface
 --------------------------

Added: trunk/contrib/scripts/sip_nat_settings
URL: http://svn.digium.com/view/asterisk/trunk/contrib/scripts/sip_nat_settings?view=auto&rev=168265
==============================================================================
--- trunk/contrib/scripts/sip_nat_settings (added)
+++ trunk/contrib/scripts/sip_nat_settings Fri Jan  9 17:04:46 2009
@@ -1,0 +1,72 @@
+#!/bin/sh
+
+# sip_nat_settings: generate NAT settings for sip.conf of an Asterisk system
+#                   that is behind a NAT router.
+#
+# This is a script to generate sane defaults for externip and localnet 
+# of sip.conf. The output should be included in the [general] section of 
+# sip.conf .
+#
+# Multiple network interfaces: If you have multiple network interfaces, 
+# this script will generate a 'localnet' line for each of them that has a 
+# broadcast (ipv4) address, except the loopback interface (lo). You can 
+# later rem-out all of those you don't need.
+# 
+# Alternatively, provide a network interface as a parameter an a localnet 
+# line will only be generated for its network.
+#
+# Copyright (C) 2005 by Tzafrir Cohen <tzafrir.cohen at xorcom.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+WGET=`which wget`
+FETCH=`which fetch`
+if [ -x ${WGET} ]; then
+	externip=`${WGET} -q -O- http://www.whatismyip.org`
+elif [ -x ${FETCH} ]; then
+	externip=`${FETCH} -q -o - http://www.whatismyip.org`
+else
+	echo "no binary found to contact http://www.whatismyip.org"
+	exit 1
+fi
+
+# optional parameter: network interface to use. By default: none.
+IFACE="$1"
+
+OS=`uname -s`
+case "$OS" in
+Linux)
+  echo "externip = $externip"
+  /sbin/ifconfig $IFACE | grep 'inet addr:' | grep Bcast \
+  | sed -e 's/^.*Bcast:\([0-9.]*\)\s*Mask:\([0-9.]*\)\s*$/localnet = \1\/\2/'
+  ;;
+OpenBSD|FreeBSD)
+  if [ "${OS}" = "FreeBSD" ]; then
+	  VER=`uname -r | cut -d . -f 1`
+	  if [ ${VER} -lt 7 ]; then
+		  echo "Unsupported OS"
+		  exit 1
+	  fi
+  fi
+  echo "externip = $externip"
+  ip=`/sbin/ifconfig $IFACE | awk '/\tinet .* broadcast/{print $6}'`
+  x=`/sbin/ifconfig $IFACE | awk '/\tinet .* broadcast/{print $4}'`
+  printf 'localnet = %s/%u.%u.%u.%u\n' $ip $(($x>>24&0xff)) $(($x>>16&0xff)) $(($x>>8&0xff)) $(($x&0xff))
+  ;;
+*)
+  echo >&2 "$0: Unsupported OS $OS"
+  exit 1
+  ;;
+esac

Propchange: trunk/contrib/scripts/sip_nat_settings
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/contrib/scripts/sip_nat_settings
------------------------------------------------------------------------------
    svn:executable = *

Propchange: trunk/contrib/scripts/sip_nat_settings
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/contrib/scripts/sip_nat_settings
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list