📜 ⬆️ ⬇️

How to find out your external IP from the program



When writing various programs for working with the network, especially p2p systems, from time to time it is necessary to find out the external IP of your computer from the program (the address where your computer is accessible from the Big Internet). Often there is a temptation to go the easy way and use external WEB-services, which by http return you the IP, or deploy it yourself. Although this way of solving the problem is workable, it nevertheless has several disadvantages:


Based on the foregoing, it becomes clear that we need a lightweight and standardized protocol for obtaining external IP, in order not to depend on the voluntarism of the owner of a site, and generally use resources efficiently.


The WWW generation will be very surprised, but such a protocol has been around for a long time, standardized and widely used in IP telephony, and in some places for other multimedia services. The protocol is called STUN and is specified in rfc5389 .


This is a lightweight protocol based on UDP, and when used, obtaining an external IP via STUN does not require the establishment of a TCP connection and so on. Compared to www, this reduces the load on computing resources, and reduces the time to determine the address. Only two packets, each approximately 50 bytes, and the address is known.


In fact, STUN allows not only to determine the external IP, but also to investigate the behavior of the current NAT barrier, which may consist of several consecutive NAT devices. But the extended functions of STUN go beyond the article on getting an IP address, so we’ll focus on the main thing.


So, the easy and standard protocol, it turns out, is. Now you need a STUN server to which your program will send requests. Fortunately, there are such servers, every self-respecting VOIP company keeps one. We are aware of several hundreds of such servers, which is much more than public web-servers of similar purpose. And all are standard, and there is no need for each of them a “special approach” in decoding the answer. Below is a list of public STUN-servers known to us.


Now that we have decided on the protocol and servers, it remains to find somewhere a STUN client that can be easily integrated into your program. Here we can advise you to take the stun.cpp file from our Emercoin project, which contains the complete external IP definition subsystem through STUN. Fortunately, the project is Open Source, and is distributed under the GPL license.


The file contains the GetExternalIPbySTUN () function, which pseudo-randomly loop through a list of predefined STUN servers until it receives a response from one of them. Thus, the failure of some servers will simply slow down the subsystem, but will not lead to a denial of service. And since the list contains more than two hundred servers, the probability of failure of all of them at the same time seems insignificant.


The pseudo-random list traversal ensures that there is no configuration for the failure of some servers, which will slow down all clients simultaneously. In addition, this algorithm scatters requests across multiple servers, which eliminates the overload of a dedicated server. That is, the load is evenly distributed throughout the server pool.


Measures are also taken to anonymize requests by generating a random ID for each request. In combination with scattering across servers, it becomes almost impossible for the owner of any server to “calculate” your p2p network. It receives less than 0.5% of requests, and cannot unambiguously separate your requests from requests originating from IP-telephony equipment.


Below is a list of public STUN-servers known to us in the format:
')

Server: port
 iphone-stun.strato-iphone.de:3478
 numb.viagenie.ca:3478
 sip1.lakedestiny.cordiaip.com:3478
 stun.12connect.com:3478
 stun.12voip.com:3478
 stun.1cbit.ru:3478
 stun.1und1.de:3478
 stun.2talk.co.nz:3478
 stun.2talk.com:3478
 stun.3clogic.com:3478
 stun.3cx.com:3478
 stun.726.com:3478
 stun.a-mm.tv:3478
 stun.aa.net.uk:3478
 stun.aceweb.com:3478
 stun.acrobits.cz:3478
 stun.acronis.com:3478
 stun.actionvoip.com:3478
 stun.advfn.com:3478
 stun.aeta-audio.com:3478
 stun.aeta.com:3478
 stun.allflac.com:3478
 stun.anlx.net:3478
 stun.antisip.com:3478
 stun.avigora.com:3478
 stun.avigora.fr:3478
 stun.b2b2c.ca:3478
 stun.bahnhof.net:3478
 stun.barracuda.com:3478
 stun.bcs2005.net:3478
 stun.beam.pro:3478
 stun.bitburger.de:3478
 stun.bluesip.net:3478
 stun.bomgar.com:3478
 stun.botonakis.com:3478
 stun.budgetphone.nl:3478
 stun.budgetsip.com:3478
 stun.cablenet-as.net:3478
 stun.callromania.ro:3478
 stun.callwithus.com:3478
 stun.cheapvoip.com:3478
 stun.cloopen.com:3478
 stun.cognitoys.com:3478
 stun.comfi.com:3478
 stun.commpeak.com:3478
 stun.communigate.com:3478
 stun.comrex.com:3478
 stun.comtube.com:3478
 stun.comtube.ru:3478
 stun.connecteddata.com:3478
 stun.cope.es:3478
 stun.counterpath.com:3478
 stun.counterpath.net:3478
 stun.crimeastar.net:3478
 stun.dcalling.de:3478
 stun.demos.ru:3478
 stun.demos.su:3478
 stun.dls.net:3478
 stun.dokom.net:3478
 stun.dowlatow.ru:3478
 stun.duocom.es:3478
 stun.dus.net:3478
 stun.e-fon.ch:3478
 stun.easemob.com:3478
 stun.easycall.pl:3478
 stun.easyvoip.com:3478
 stun.eibach.de:3478
 stun.ekiga.net:3478
 stun.ekir.de:3478
 stun.elitetele.com:3478
 stun.emu.ee:3478
 stun.engineeredarts.co.uk:3478
 stun.eoni.com:3478
 stun.epygi.com:3478
 stun.faktortel.com.au:3478
 stun.fbsbx.com:3478
 stun.fh-stralsund.de:3478
 stun.fmbaros.ru:3478
 stun.fmo.de:3478
 stun.freecall.com:3478
 stun.freeswitch.org:3478
 stun.freevoipdeal.com:3478
 stun.genymotion.com:3478
 stun.gmx.de:3478
 stun.gmx.net:3478
 stun.gnunet.org:3478
 stun.gradwell.com:3478
 stun.halonet.pl:3478
 stun.highfidelity.io:3478
 stun.hoiio.com:3478
 stun.hosteurope.de:3478
 stun.i-stroy.ru:3478
 stun.ideasip.com:3478
 stun.imweb.io:3478
 stun.infra.net:3478
 stun.innovaphone.com:3478
 stun.instantteleseminar.com:3478
 stun.internetcalls.com:3478
 stun.intervoip.com:3478
 stun.ipcomms.net:3478
 stun.ipfire.org:3478
 stun.ippi.com:3478
 stun.ippi.fr:3478
 stun.it1.hr:3478
 stun.ivao.aero:3478
 stun.jabbim.cz:3478
 stun.jumblo.com:3478
 stun.justvoip.com:3478
 stun.kaospilot.dk:3478
 stun.kaseya.com:3478
 stun.kaznpu.kz:3478
 stun.kiwilink.co.nz:3478
 stun.kuaibo.com:3478
 stun.l.google.com:19302
 stun.lamobo.org:3478
 stun.levigo.de:3478
 stun.lindab.com:3478
 stun.linphone.org:3478
 stun.linx.net:3478
 stun.liveo.fr:3478
 stun.lowratevoip.com:3478
 stun.lundimatin.fr:3478
 stun.maestroconference.com:3478
 stun.mangotele.com:3478
 stun.mgn.ru:3478
 stun.mit.de:3478
 stun.miwifi.com:3478
 stun.mixer.com:3478
 stun.modulus.gr:3478
 stun.mrmondialisation.org:3478
 stun.myfreecams.com:3478
 stun.myvoiptraffic.com:3478
 stun.mywatson.it:3478
 stun.nacsworld.com:3478
 stun.nas.net:3478
 stun.nautile.nc:3478
 stun.netappel.com:3478
 stun.nextcloud.com:3478
 stun.nfon.net:3478
 stun.ngine.de:3478
 stun.noblogs.org:3478
 stun.node4.co.uk:3478
 stun.nonoh.net:3478
 stun.nottingham.ac.uk:3478
 stun.nova.is:3478
 stun.onesuite.com:3478
 stun.onthenet.com.au:3478
 stun.ooma.com:3478
 stun.oovoo.com:3478
 stun.ozekiphone.com:3478
 stun.personal-voip.de:3478
 stun.petcube.com:3478
 stun.pexip.com:3478
 stun.phone.com:3478
 stun.pidgin.im:3478
 stun.pjsip.org:3478
 stun.planete.net:3478
 stun.poivy.com:3478
 stun.powervoip.com:3478
 stun.ppdi.com:3478
 stun.rackco.com:3478
 stun.redworks.nl:3478
 stun.ringostat.com:3478
 stun.rmf.pl:3478
 stun.rockenstein.de:3478
 stun.rolmail.net:3478
 stun.rudtp.ru:3478
 stun.russian-club.net:3478
 stun.rynga.com:3478
 stun.sainf.ru:3478
 stun.schlund.de:3478
 stun.sigmavoip.com:3478
 stun.sip.us:3478
 stun.sipdiscount.com:3478
 stun.sipgate.net:10000
 stun.sipgate.net:3478
 stun.siplogin.de:3478
 stun.sipnet.net:3478
 stun.sipnet.ru:3478
 stun.siportal.it:3478
 stun.sippeer.dk:3478
 stun.siptraffic.com:3478
 stun.sma.de:3478
 stun.smartvoip.com:3478
 stun.smsdiscount.com:3478
 stun.snafu.de:3478
 stun.solcon.nl:3478
 stun.solnet.ch:3478
 stun.sonetel.com:3478
 stun.sonetel.net:3478
 stun.sovtest.ru:3478
 stun.speedy.com.ar:3478
 stun.spoiltheprincess.com:3478
 stun.srce.hr:3478
 stun.ssl7.net:3478
 stun.stunprotocol.org
 stun.swissquote.com:3478
 stun.t-online.de:3478
 stun.talks.by:3478
 stun.tel.lu:3478
 stun.telbo.com:3478
 stun.telefacil.com:3478
 stun.threema.ch:3478
 stun.tng.de:3478
 stun.trueconf.ru:3478
 stun.twt.it:3478
 stun.ucsb.edu:3478
 stun.ucw.cz:3478
 stun.uiscom.ru:3478
 stun.uls.co.za:3478
 stun.unseen.is:3478
 stun.up.edu.ph:3478
 stun.usfamily.net:3478
 stun.uucall.com:3478
 stun.veoh.com:3478
 stun.vipgroup.net:3478
 stun.viva.gr:3478
 stun.vivox.com:3478
 stun.vline.com:3478
 stun.vmi.se:3478
 stun.vo.lu:3478
 stun.vodafone.ro:3478
 stun.voicetrading.com:3478
 stun.voip.aebc.com:3478
 stun.voip.blackberry.com:34:34
 stun.voip.eutelia.it:3478
 stun.voiparound.com:3478
 stun.voipblast.com:3478
 stun.voipbuster.com:3478
 stun.voipbusterpro.com:3478
 stun.voipcheap.co.uk:3478
 stun.voipcheap.com:3478
 stun.voipdiscount.com:3478
 stun.voipfibre.com:3478
 stun.voipgain.com:3478
 stun.voipgate.com:3478
 stun.voipinfocenter.com:3478
 stun.voipplanet.nl:3478
 stun.voippro.com:3478
 stun.voipraider.com:3478
 stun.voipstunt.com:3478
 stun.voipwise.com:3478
 stun.voipzoom.com:3478
 stun.voxgratia.org:3478
 stun.voxox.com:3478
 stun.voztele.com:3478
 stun.wcoil.com:3478
 stun.webcalldirect.com:3478
 stun.whc.net:3478
 stun.whoi.edu:3478
 stun.wifirst.net:3478
 stun.wtfismyip.com:3478
 stun.wwdl.net:3478
 stun.xn ---- 8sbcoa5btidn9i.xn - p1ai: 3478
 stun.xten.com:3478
 stun.xtratelecom.es:3478
 stun.yy.com:3478
 stun.zadarma.com:3478
 stun.zepter.ru:3478
 stun.zoiper.com:3478
 stun1.faktortel.com.au:3478
 stun2.faktortel.com.au:3478
 stun1.l.google.com:19302
 stun2.l.google.com:19:19
 stun3.l.google.com:19302
 stun4.l.google.com:19302

Source: https://habr.com/ru/post/335458/


All Articles