On 1/17/06, Ian Darwin <[EMAIL PROTECTED]> wrote:
>
> Dave Donovan wrote:
> <SNIP>
> The main line could be just:
>
> echo SET VARIABLE IPADDR \"$(ifconfig eth0 | awk -F: '$1 = /inet
> addr/{print $2}')\"
>
> i.e., awk | cut is usually redundant.
>
> And don't forget, this only works on a system with only one interface, and
> only on
> Linux where you don't get device-specific interface names (e.g, it will
> fail on Solaris,
> OpenBSD, NetBSD, FreeBSD, HP/UX, AIX and just about every other *NIX out
> there).
> On at least OpenBSD you could change "eth0" to "egress" and have it
> probably work (you'd
> also remove the -F" and the " addr".
>
> My real point is that relying on the output format of ifconfig is
> inherently risky.
>
> Ian
>
>
> Here is a silly little perl script that will output the IP address
associated with the hostname:
#!/usr/bin/perl
use Socket;
chop($hostname = `hostname`);
$packed = gethostbyname($hostname);
$address = inet_ntoa($packed);
print "SET VARIABLE IPADDR $address\n";

This should work on most systems (only tested on Asterisk at home 2.2(CentOS
4.2), ubuntu 5.10 and Windows, both ActivePerl and cygwin perl).

--
sacha

Reply via email to