2

Is there some command line function within FreeNAS (FreeBSD) derivative which could return my external address? Since that same address is synchronized with DynDns (via router), in C# I retrieved that via DNS query like this:

var hostEntry = Dns.GetHostEntry("myexternalname.dyndns.org");
foreach (var iAddress in hostEntry.AddressList) {
    if (iAddress.AddressFamily == AddressFamily.InterNetwork) {
        MessageBox.Show(iAddress);
    }
}
Josip Medved
  • 1,674
  • 2
  • 18
  • 18

3 Answers3

2

Prerequisites

  • dig
  • gnu grep
  • gnu tr
  • gnu awk
  • sort
  • uniq

From a command line:

dig yourserver.dyndns.org | grep "IN" | grep "[0-9]" | awk '{print $5}' | sort | uniq 

The good:

  • Very simple pipe sequence returns at a minimum one IP address.
  • Can handle multiple IP addresses for the same name.

The bad:

  • pumps out text as a result, which means you'll probably need a redirect to a file
  • I can think of at least one edge case where this script might fail, although it's "good enough"

The ugly:

  • Script is far from optimal. I just banged it out in a few minutes.
  • Too many command line dependencies.
  • While the commands are fairly generic, the tool chain is GNU-specific.
  • Better off written in perl or python as a monolithic script.
Avery Payne
  • 14,326
  • 1
  • 48
  • 87
2

here is my favorite command :

wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

simple. clear. and if you have curl :

curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
Razique
  • 2,266
  • 1
  • 19
  • 23
2

I found command that works on FreeNAS.

# host myexternalname.dyndns.org

It returns

myexternalname.dyndns.org      A       89.172.197.320

From that I just use awk:

host myexternalname.dyndns.org | awk '{ print $3; }'

and that returns just IP:

89.172.197.320

P.S. I know that 89.172.197.320 is not real IP address. I wrote it like that in order not to share mine IP address (or IP address from someone else).

P.P.S. Thanks for help to Kronick and Avery Payne since their ideas pushed me in right direction.

Josip Medved
  • 1,674
  • 2
  • 18
  • 18
  • Gotta love those cut-down distros. At least FreeNAS is a bit more flexible than Smoothwall (another cut-down distro), as it's based on FreeBSD you can copy the software you need via SCP if you're desperate... – Mark Henderson Aug 27 '09 at 21:19