Minimal STUN client for finding external IP

Alexander Kriegisch kriegaex at freetz.org
Thu Dec 15 16:18:28 UTC 2011


I am following up on this topic because Vladislav Grishenko was nice
enough to provide me with some C code borrowed from Asterisk. Basically
ministun is a basic stand-alone STUN client which determines the
external IP ("mapped address" in STUN speak) and prints it to stdout. On
my platform (mipsel) the stripped binary's size is just 7 KB, but I
guess if it would utilise the Busybox infrastructure and be optimised by
an expert to the bare minimum, it would be even smaller. Evan as it is
now, it is fast as hell. :)

Feel free to get the code from our project:

Changeset: http://freetz.org/changeset/8235
SVN checkout: http://svn.freetz.org/trunk

Many thanks to Vladislav
--
Alexander Kriegisch (kriegaex)
http://freetz.org

Alexander Kriegisch, 15.12.2011 13:02:
> Someone in our project had the idea of using a STUN client like the
> one at https://sourceforge.net/projects/stun to determine a router's
> external IP address quickly and efficiently. Actually this is much
> faster than wget-ting the address from an external site via HTTP
> request. We tested this on a desktop Linux system. BTW, the IP can be
> determined like this:
> 
> stun -v 1 stun.1und1.de 2>&1 | sed -nr 's/^MappedAddress = (.*):.*$/\1/p'
> 
> Now the STUN package mentioned above is coded in C++ and does a lot
> more than just determine. I had the idea that having a minimal
> stun_get_ip Applet in BB would be a nice thing, because BB runs on
> many embedded systems, many of them router firmwares, and it is a
> common task to determine an external IP address from behind a NAT.
> 
> I know that I should rather provide a patch than ask for one, but
> unfortunately I do not speak C. Maybe there is a developer on this
> list who has a similar use case and would volunteer to implement a
> minimal STUN IP detection applet which could be used like this:
> 
> stun_get_ip stun_server
> 
> A full port of the STUN test client with the complete suite of three
> test methods might be useful for others, but me personally, I do not
> need it.
> 
> I hope you do not mind me asking for a new applet on this list, I
> hope it is the right place for it. I am not greedy, so if nobody sees
> any value in it or it is too expensive to implement, it is okay and
> we continue to use the slower method of querying the address via
> HTTP. STUN was made for NAT traversal though, so it seems like the
> natural solution to this problem.


More information about the busybox mailing list