Minimal STUN client for finding external IP

Vladislav Grishenko themiron at mail.ru
Thu Dec 15 17:36:28 UTC 2011


Hi Alex,
I've made standalone ministun for the same reasons (get external ip behind
nat) in 2009 for one of my projects, but didn't publish it as well.
Feel free to use, and yes, it could be even smaller using libbb and/or
lowering printout level.

Best Regards, Vladislav Grishenko

> -----Original Message-----
> From: Alexander Kriegisch [mailto:kriegaex at freetz.org]
> Sent: Thursday, December 15, 2011 10:18 PM
> To: busybox at busybox.net
> Cc: themiron at mail.ru
> Subject: Re: Minimal STUN client for finding external IP
> 
> 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