diff --git a/Program.cs b/Program.cs index 2b16968..5e502a6 100644 --- a/Program.cs +++ b/Program.cs @@ -7,7 +7,7 @@ namespace p2pcopy { - class Program + static class Program { static void Main(string[] args) { @@ -26,7 +26,7 @@ static void Main(string[] args) return; } - if (cla.File != null && (!(File.Exists(cla.File)))) + if (cla.File != null && !File.Exists(cla.File)) { Console.Error.WriteLine($"File {cla.File} does not exist"); Environment.Exit(2); @@ -42,7 +42,6 @@ static void Main(string[] args) try { - if (cla.LocalPort != -1) { Console.WriteLine("Using local port: {0}", cla.LocalPort); @@ -182,280 +181,279 @@ static P2pEndPoint GetExternalEndPoint(Socket socket) { // https://gist.github.com/zziuni/3741933 - List> stunServers = new List>(); - stunServers.Add(new Tuple("stun.l.google.com", 19302)); - stunServers.Add(new Tuple("iphone-stun.strato-iphone.de", 3478)); - stunServers.Add(new Tuple("numb.viagenie.ca", 3478)); - stunServers.Add(new Tuple("s1.taraba.net", 3478)); - stunServers.Add(new Tuple("s2.taraba.net", 3478)); - stunServers.Add(new Tuple("stun.12connect.com", 3478)); - stunServers.Add(new Tuple("stun.12voip.com", 3478)); - stunServers.Add(new Tuple("stun.1und1.de", 3478)); - stunServers.Add(new Tuple("stun.2talk.co.nz", 3478)); - stunServers.Add(new Tuple("stun.2talk.com", 3478)); - stunServers.Add(new Tuple("stun.3clogic.com", 3478)); - stunServers.Add(new Tuple("stun.3cx.com", 3478)); - stunServers.Add(new Tuple("stun.a-mm.tv", 3478)); - stunServers.Add(new Tuple("stun.aa.net.uk", 3478)); - stunServers.Add(new Tuple("stun.acrobits.cz", 3478)); - stunServers.Add(new Tuple("stun.actionvoip.com", 3478)); - stunServers.Add(new Tuple("stun.advfn.com", 3478)); - stunServers.Add(new Tuple("stun.aeta-audio.com", 3478)); - stunServers.Add(new Tuple("stun.aeta.com", 3478)); - stunServers.Add(new Tuple("stun.alltel.com.au", 3478)); - stunServers.Add(new Tuple("stun.altar.com.pl", 3478)); - stunServers.Add(new Tuple("stun.annatel.net", 3478)); - stunServers.Add(new Tuple("stun.antisip.com", 3478)); - stunServers.Add(new Tuple("stun.arbuz.ru", 3478)); - stunServers.Add(new Tuple("stun.avigora.com", 3478)); - stunServers.Add(new Tuple("stun.avigora.fr", 3478)); - stunServers.Add(new Tuple("stun.awa-shima.com", 3478)); - stunServers.Add(new Tuple("stun.awt.be", 3478)); - stunServers.Add(new Tuple("stun.b2b2c.ca", 3478)); - stunServers.Add(new Tuple("stun.bahnhof.net", 3478)); - stunServers.Add(new Tuple("stun.barracuda.com", 3478)); - stunServers.Add(new Tuple("stun.bluesip.net", 3478)); - stunServers.Add(new Tuple("stun.bmwgs.cz", 3478)); - stunServers.Add(new Tuple("stun.botonakis.com", 3478)); - stunServers.Add(new Tuple("stun.budgetphone.nl", 3478)); - stunServers.Add(new Tuple("stun.budgetsip.com", 3478)); - stunServers.Add(new Tuple("stun.cablenet-as.net", 3478)); - stunServers.Add(new Tuple("stun.callromania.ro", 3478)); - stunServers.Add(new Tuple("stun.callwithus.com", 3478)); - stunServers.Add(new Tuple("stun.cbsys.net", 3478)); - stunServers.Add(new Tuple("stun.chathelp.ru", 3478)); - stunServers.Add(new Tuple("stun.cheapvoip.com", 3478)); - stunServers.Add(new Tuple("stun.ciktel.com", 3478)); - stunServers.Add(new Tuple("stun.cloopen.com", 3478)); - stunServers.Add(new Tuple("stun.colouredlines.com.au", 3478)); - stunServers.Add(new Tuple("stun.comfi.com", 3478)); - stunServers.Add(new Tuple("stun.commpeak.com", 3478)); - stunServers.Add(new Tuple("stun.comtube.com", 3478)); - stunServers.Add(new Tuple("stun.comtube.ru", 3478)); - stunServers.Add(new Tuple("stun.cope.es", 3478)); - stunServers.Add(new Tuple("stun.counterpath.com", 3478)); - stunServers.Add(new Tuple("stun.counterpath.net", 3478)); - stunServers.Add(new Tuple("stun.cryptonit.net", 3478)); - stunServers.Add(new Tuple("stun.darioflaccovio.it", 3478)); - stunServers.Add(new Tuple("stun.datamanagement.it", 3478)); - stunServers.Add(new Tuple("stun.dcalling.de", 3478)); - stunServers.Add(new Tuple("stun.decanet.fr", 3478)); - stunServers.Add(new Tuple("stun.demos.ru", 3478)); - stunServers.Add(new Tuple("stun.develz.org", 3478)); - stunServers.Add(new Tuple("stun.dingaling.ca", 3478)); - stunServers.Add(new Tuple("stun.doublerobotics.com", 3478)); - stunServers.Add(new Tuple("stun.drogon.net", 3478)); - stunServers.Add(new Tuple("stun.duocom.es", 3478)); - stunServers.Add(new Tuple("stun.dus.net", 3478)); - stunServers.Add(new Tuple("stun.e-fon.ch", 3478)); - stunServers.Add(new Tuple("stun.easybell.de", 3478)); - stunServers.Add(new Tuple("stun.easycall.pl", 3478)); - stunServers.Add(new Tuple("stun.easyvoip.com", 3478)); - stunServers.Add(new Tuple("stun.efficace-factory.com", 3478)); - stunServers.Add(new Tuple("stun.einsundeins.com", 3478)); - stunServers.Add(new Tuple("stun.einsundeins.de", 3478)); - stunServers.Add(new Tuple("stun.ekiga.net", 3478)); - stunServers.Add(new Tuple("stun.epygi.com", 3478)); - stunServers.Add(new Tuple("stun.etoilediese.fr", 3478)); - stunServers.Add(new Tuple("stun.eyeball.com", 3478)); - stunServers.Add(new Tuple("stun.faktortel.com.au", 3478)); - stunServers.Add(new Tuple("stun.freecall.com", 3478)); - stunServers.Add(new Tuple("stun.freeswitch.org", 3478)); - stunServers.Add(new Tuple("stun.freevoipdeal.com", 3478)); - stunServers.Add(new Tuple("stun.fuzemeeting.com", 3478)); - stunServers.Add(new Tuple("stun.gmx.de", 3478)); - stunServers.Add(new Tuple("stun.gmx.net", 3478)); - stunServers.Add(new Tuple("stun.gradwell.com", 3478)); - stunServers.Add(new Tuple("stun.halonet.pl", 3478)); - stunServers.Add(new Tuple("stun.hellonanu.com", 3478)); - stunServers.Add(new Tuple("stun.hoiio.com", 3478)); - stunServers.Add(new Tuple("stun.hosteurope.de", 3478)); - stunServers.Add(new Tuple("stun.ideasip.com", 3478)); - stunServers.Add(new Tuple("stun.imesh.com", 3478)); - stunServers.Add(new Tuple("stun.infra.net", 3478)); - stunServers.Add(new Tuple("stun.internetcalls.com", 3478)); - stunServers.Add(new Tuple("stun.intervoip.com", 3478)); - stunServers.Add(new Tuple("stun.ipcomms.net", 3478)); - stunServers.Add(new Tuple("stun.ipfire.org", 3478)); - stunServers.Add(new Tuple("stun.ippi.fr", 3478)); - stunServers.Add(new Tuple("stun.ipshka.com", 3478)); - stunServers.Add(new Tuple("stun.iptel.org", 3478)); - stunServers.Add(new Tuple("stun.irian.at", 3478)); - stunServers.Add(new Tuple("stun.it1.hr", 3478)); - stunServers.Add(new Tuple("stun.ivao.aero", 3478)); - stunServers.Add(new Tuple("stun.jappix.com", 3478)); - stunServers.Add(new Tuple("stun.jumblo.com", 3478)); - stunServers.Add(new Tuple("stun.justvoip.com", 3478)); - stunServers.Add(new Tuple("stun.kanet.ru", 3478)); - stunServers.Add(new Tuple("stun.kiwilink.co.nz", 3478)); - stunServers.Add(new Tuple("stun.kundenserver.de", 3478)); - stunServers.Add(new Tuple("stun.linea7.net", 3478)); - stunServers.Add(new Tuple("stun.linphone.org", 3478)); - stunServers.Add(new Tuple("stun.liveo.fr", 3478)); - stunServers.Add(new Tuple("stun.lowratevoip.com", 3478)); - stunServers.Add(new Tuple("stun.lugosoft.com", 3478)); - stunServers.Add(new Tuple("stun.lundimatin.fr", 3478)); - stunServers.Add(new Tuple("stun.magnet.ie", 3478)); - stunServers.Add(new Tuple("stun.manle.com", 3478)); - stunServers.Add(new Tuple("stun.mgn.ru", 3478)); - stunServers.Add(new Tuple("stun.mit.de", 3478)); - stunServers.Add(new Tuple("stun.mitake.com.tw", 3478)); - stunServers.Add(new Tuple("stun.miwifi.com", 3478)); - stunServers.Add(new Tuple("stun.modulus.gr", 3478)); - stunServers.Add(new Tuple("stun.mozcom.com", 3478)); - stunServers.Add(new Tuple("stun.myvoiptraffic.com", 3478)); - stunServers.Add(new Tuple("stun.mywatson.it", 3478)); - stunServers.Add(new Tuple("stun.nas.net", 3478)); - stunServers.Add(new Tuple("stun.neotel.co.za", 3478)); - stunServers.Add(new Tuple("stun.netappel.com", 3478)); - stunServers.Add(new Tuple("stun.netappel.fr", 3478)); - stunServers.Add(new Tuple("stun.netgsm.com.tr", 3478)); - stunServers.Add(new Tuple("stun.nfon.net", 3478)); - stunServers.Add(new Tuple("stun.noblogs.org", 3478)); - stunServers.Add(new Tuple("stun.noc.ams-ix.net", 3478)); - stunServers.Add(new Tuple("stun.node4.co.uk", 3478)); - stunServers.Add(new Tuple("stun.nonoh.net", 3478)); - stunServers.Add(new Tuple("stun.nottingham.ac.uk", 3478)); - stunServers.Add(new Tuple("stun.nova.is", 3478)); - stunServers.Add(new Tuple("stun.nventure.com", 3478)); - stunServers.Add(new Tuple("stun.on.net.mk", 3478)); - stunServers.Add(new Tuple("stun.ooma.com", 3478)); - stunServers.Add(new Tuple("stun.ooonet.ru", 3478)); - stunServers.Add(new Tuple("stun.oriontelekom.rs", 3478)); - stunServers.Add(new Tuple("stun.outland-net.de", 3478)); - stunServers.Add(new Tuple("stun.ozekiphone.com", 3478)); - stunServers.Add(new Tuple("stun.patlive.com", 3478)); - stunServers.Add(new Tuple("stun.personal-voip.de", 3478)); - stunServers.Add(new Tuple("stun.petcube.com", 3478)); - stunServers.Add(new Tuple("stun.phone.com", 3478)); - stunServers.Add(new Tuple("stun.phoneserve.com", 3478)); - stunServers.Add(new Tuple("stun.pjsip.org", 3478)); - stunServers.Add(new Tuple("stun.poivy.com", 3478)); - stunServers.Add(new Tuple("stun.powerpbx.org", 3478)); - stunServers.Add(new Tuple("stun.powervoip.com", 3478)); - stunServers.Add(new Tuple("stun.ppdi.com", 3478)); - stunServers.Add(new Tuple("stun.prizee.com", 3478)); - stunServers.Add(new Tuple("stun.qq.com", 3478)); - stunServers.Add(new Tuple("stun.qvod.com", 3478)); - stunServers.Add(new Tuple("stun.rackco.com", 3478)); - stunServers.Add(new Tuple("stun.rapidnet.de", 3478)); - stunServers.Add(new Tuple("stun.rb-net.com", 3478)); - stunServers.Add(new Tuple("stun.refint.net", 3478)); - stunServers.Add(new Tuple("stun.remote-learner.net", 3478)); - stunServers.Add(new Tuple("stun.rixtelecom.se", 3478)); - stunServers.Add(new Tuple("stun.rockenstein.de", 3478)); - stunServers.Add(new Tuple("stun.rolmail.net", 3478)); - stunServers.Add(new Tuple("stun.rounds.com", 3478)); - stunServers.Add(new Tuple("stun.rynga.com", 3478)); - stunServers.Add(new Tuple("stun.samsungsmartcam.com", 3478)); - stunServers.Add(new Tuple("stun.schlund.de", 3478)); - stunServers.Add(new Tuple("stun.services.mozilla.com", 3478)); - stunServers.Add(new Tuple("stun.sigmavoip.com", 3478)); - stunServers.Add(new Tuple("stun.sip.us", 3478)); - stunServers.Add(new Tuple("stun.sipdiscount.com", 3478)); - stunServers.Add(new Tuple("stun.sipgate.net", 10000)); - stunServers.Add(new Tuple("stun.sipgate.net", 3478)); - stunServers.Add(new Tuple("stun.siplogin.de", 3478)); - stunServers.Add(new Tuple("stun.sipnet.net", 3478)); - stunServers.Add(new Tuple("stun.sipnet.ru", 3478)); - stunServers.Add(new Tuple("stun.siportal.it", 3478)); - stunServers.Add(new Tuple("stun.sippeer.dk", 3478)); - stunServers.Add(new Tuple("stun.siptraffic.com", 3478)); - stunServers.Add(new Tuple("stun.skylink.ru", 3478)); - stunServers.Add(new Tuple("stun.sma.de", 3478)); - stunServers.Add(new Tuple("stun.smartvoip.com", 3478)); - stunServers.Add(new Tuple("stun.smsdiscount.com", 3478)); - stunServers.Add(new Tuple("stun.snafu.de", 3478)); - stunServers.Add(new Tuple("stun.softjoys.com", 3478)); - stunServers.Add(new Tuple("stun.solcon.nl", 3478)); - stunServers.Add(new Tuple("stun.solnet.ch", 3478)); - stunServers.Add(new Tuple("stun.sonetel.com", 3478)); - stunServers.Add(new Tuple("stun.sonetel.net", 3478)); - stunServers.Add(new Tuple("stun.sovtest.ru", 3478)); - stunServers.Add(new Tuple("stun.speedy.com.ar", 3478)); - stunServers.Add(new Tuple("stun.spokn.com", 3478)); - stunServers.Add(new Tuple("stun.srce.hr", 3478)); - stunServers.Add(new Tuple("stun.ssl7.net", 3478)); - stunServers.Add(new Tuple("stun.stunprotocol.org", 3478)); - stunServers.Add(new Tuple("stun.symform.com", 3478)); - stunServers.Add(new Tuple("stun.symplicity.com", 3478)); - stunServers.Add(new Tuple("stun.sysadminman.net", 3478)); - stunServers.Add(new Tuple("stun.t-online.de", 3478)); - stunServers.Add(new Tuple("stun.tagan.ru", 3478)); - stunServers.Add(new Tuple("stun.tatneft.ru", 3478)); - stunServers.Add(new Tuple("stun.teachercreated.com", 3478)); - stunServers.Add(new Tuple("stun.tel.lu", 3478)); - stunServers.Add(new Tuple("stun.telbo.com", 3478)); - stunServers.Add(new Tuple("stun.telefacil.com", 3478)); - stunServers.Add(new Tuple("stun.tis-dialog.ru", 3478)); - stunServers.Add(new Tuple("stun.tng.de", 3478)); - stunServers.Add(new Tuple("stun.twt.it", 3478)); - stunServers.Add(new Tuple("stun.u-blox.com", 3478)); - stunServers.Add(new Tuple("stun.ucallweconn.net", 3478)); - stunServers.Add(new Tuple("stun.ucsb.edu", 3478)); - stunServers.Add(new Tuple("stun.ucw.cz", 3478)); - stunServers.Add(new Tuple("stun.uls.co.za", 3478)); - stunServers.Add(new Tuple("stun.unseen.is", 3478)); - stunServers.Add(new Tuple("stun.usfamily.net", 3478)); - stunServers.Add(new Tuple("stun.veoh.com", 3478)); - stunServers.Add(new Tuple("stun.vidyo.com", 3478)); - stunServers.Add(new Tuple("stun.vipgroup.net", 3478)); - stunServers.Add(new Tuple("stun.virtual-call.com", 3478)); - stunServers.Add(new Tuple("stun.viva.gr", 3478)); - stunServers.Add(new Tuple("stun.vivox.com", 3478)); - stunServers.Add(new Tuple("stun.vline.com", 3478)); - stunServers.Add(new Tuple("stun.vo.lu", 3478)); - stunServers.Add(new Tuple("stun.vodafone.ro", 3478)); - stunServers.Add(new Tuple("stun.voicetrading.com", 3478)); - stunServers.Add(new Tuple("stun.voip.aebc.com", 3478)); - stunServers.Add(new Tuple("stun.voip.blackberry.com", 3478)); - stunServers.Add(new Tuple("stun.voip.eutelia.it", 3478)); - stunServers.Add(new Tuple("stun.voiparound.com", 3478)); - stunServers.Add(new Tuple("stun.voipblast.com", 3478)); - stunServers.Add(new Tuple("stun.voipbuster.com", 3478)); - stunServers.Add(new Tuple("stun.voipbusterpro.com", 3478)); - stunServers.Add(new Tuple("stun.voipcheap.co.uk", 3478)); - stunServers.Add(new Tuple("stun.voipcheap.com", 3478)); - stunServers.Add(new Tuple("stun.voipfibre.com", 3478)); - stunServers.Add(new Tuple("stun.voipgain.com", 3478)); - stunServers.Add(new Tuple("stun.voipgate.com", 3478)); - stunServers.Add(new Tuple("stun.voipinfocenter.com", 3478)); - stunServers.Add(new Tuple("stun.voipplanet.nl", 3478)); - stunServers.Add(new Tuple("stun.voippro.com", 3478)); - stunServers.Add(new Tuple("stun.voipraider.com", 3478)); - stunServers.Add(new Tuple("stun.voipstunt.com", 3478)); - stunServers.Add(new Tuple("stun.voipwise.com", 3478)); - stunServers.Add(new Tuple("stun.voipzoom.com", 3478)); - stunServers.Add(new Tuple("stun.vopium.com", 3478)); - stunServers.Add(new Tuple("stun.voxgratia.org", 3478)); - stunServers.Add(new Tuple("stun.voxox.com", 3478)); - stunServers.Add(new Tuple("stun.voys.nl", 3478)); - stunServers.Add(new Tuple("stun.voztele.com", 3478)); - stunServers.Add(new Tuple("stun.vyke.com", 3478)); - stunServers.Add(new Tuple("stun.webcalldirect.com", 3478)); - stunServers.Add(new Tuple("stun.whoi.edu", 3478)); - stunServers.Add(new Tuple("stun.wifirst.net", 3478)); - stunServers.Add(new Tuple("stun.wwdl.net", 3478)); - stunServers.Add(new Tuple("stun.xs4all.nl", 3478)); - stunServers.Add(new Tuple("stun.xtratelecom.es", 3478)); - stunServers.Add(new Tuple("stun.yesss.at", 3478)); - stunServers.Add(new Tuple("stun.zadarma.com", 3478)); - stunServers.Add(new Tuple("stun.zadv.com", 3478)); - stunServers.Add(new Tuple("stun.zoiper.com", 3478)); - stunServers.Add(new Tuple("stun1.faktortel.com.au", 3478)); - stunServers.Add(new Tuple("stun1.l.google.com", 19302)); - stunServers.Add(new Tuple("stun1.voiceeclipse.net", 3478)); - stunServers.Add(new Tuple("stun2.l.google.com", 19302)); - stunServers.Add(new Tuple("stun3.l.google.com", 19302)); - stunServers.Add(new Tuple("stun4.l.google.com", 19302)); - stunServers.Add(new Tuple("stunserver.org", 3478)); + List<(string Host, int Port)> stunServers = new() + { + ("stun.l.google.com", 19302), + ("iphone-stun.strato-iphone.de", 3478), + ("numb.viagenie.ca", 3478), + ("s1.taraba.net", 3478), + ("s2.taraba.net", 3478), + ("stun.12connect.com", 3478), + ("stun.12voip.com", 3478), + ("stun.1und1.de", 3478), + ("stun.2talk.co.nz", 3478), + ("stun.2talk.com", 3478), + ("stun.3clogic.com", 3478), + ("stun.3cx.com", 3478), + ("stun.a-mm.tv", 3478), + ("stun.aa.net.uk", 3478), + ("stun.acrobits.cz", 3478), + ("stun.actionvoip.com", 3478), + ("stun.advfn.com", 3478), + ("stun.aeta-audio.com", 3478), + ("stun.aeta.com", 3478), + ("stun.alltel.com.au", 3478), + ("stun.altar.com.pl", 3478), + ("stun.annatel.net", 3478), + ("stun.antisip.com", 3478), + ("stun.arbuz.ru", 3478), + ("stun.avigora.com", 3478), + ("stun.avigora.fr", 3478), + ("stun.awa-shima.com", 3478), + ("stun.awt.be", 3478), + ("stun.b2b2c.ca", 3478), + ("stun.bahnhof.net", 3478), + ("stun.barracuda.com", 3478), + ("stun.bluesip.net", 3478), + ("stun.bmwgs.cz", 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.cbsys.net", 3478), + ("stun.chathelp.ru", 3478), + ("stun.cheapvoip.com", 3478), + ("stun.ciktel.com", 3478), + ("stun.cloopen.com", 3478), + ("stun.colouredlines.com.au", 3478), + ("stun.comfi.com", 3478), + ("stun.commpeak.com", 3478), + ("stun.comtube.com", 3478), + ("stun.comtube.ru", 3478), + ("stun.cope.es", 3478), + ("stun.counterpath.com", 3478), + ("stun.counterpath.net", 3478), + ("stun.cryptonit.net", 3478), + ("stun.darioflaccovio.it", 3478), + ("stun.datamanagement.it", 3478), + ("stun.dcalling.de", 3478), + ("stun.decanet.fr", 3478), + ("stun.demos.ru", 3478), + ("stun.develz.org", 3478), + ("stun.dingaling.ca", 3478), + ("stun.doublerobotics.com", 3478), + ("stun.drogon.net", 3478), + ("stun.duocom.es", 3478), + ("stun.dus.net", 3478), + ("stun.e-fon.ch", 3478), + ("stun.easybell.de", 3478), + ("stun.easycall.pl", 3478), + ("stun.easyvoip.com", 3478), + ("stun.efficace-factory.com", 3478), + ("stun.einsundeins.com", 3478), + ("stun.einsundeins.de", 3478), + ("stun.ekiga.net", 3478), + ("stun.epygi.com", 3478), + ("stun.etoilediese.fr", 3478), + ("stun.eyeball.com", 3478), + ("stun.faktortel.com.au", 3478), + ("stun.freecall.com", 3478), + ("stun.freeswitch.org", 3478), + ("stun.freevoipdeal.com", 3478), + ("stun.fuzemeeting.com", 3478), + ("stun.gmx.de", 3478), + ("stun.gmx.net", 3478), + ("stun.gradwell.com", 3478), + ("stun.halonet.pl", 3478), + ("stun.hellonanu.com", 3478), + ("stun.hoiio.com", 3478), + ("stun.hosteurope.de", 3478), + ("stun.ideasip.com", 3478), + ("stun.imesh.com", 3478), + ("stun.infra.net", 3478), + ("stun.internetcalls.com", 3478), + ("stun.intervoip.com", 3478), + ("stun.ipcomms.net", 3478), + ("stun.ipfire.org", 3478), + ("stun.ippi.fr", 3478), + ("stun.ipshka.com", 3478), + ("stun.iptel.org", 3478), + ("stun.irian.at", 3478), + ("stun.it1.hr", 3478), + ("stun.ivao.aero", 3478), + ("stun.jappix.com", 3478), + ("stun.jumblo.com", 3478), + ("stun.justvoip.com", 3478), + ("stun.kanet.ru", 3478), + ("stun.kiwilink.co.nz", 3478), + ("stun.kundenserver.de", 3478), + ("stun.linea7.net", 3478), + ("stun.linphone.org", 3478), + ("stun.liveo.fr", 3478), + ("stun.lowratevoip.com", 3478), + ("stun.lugosoft.com", 3478), + ("stun.lundimatin.fr", 3478), + ("stun.magnet.ie", 3478), + ("stun.manle.com", 3478), + ("stun.mgn.ru", 3478), + ("stun.mit.de", 3478), + ("stun.mitake.com.tw", 3478), + ("stun.miwifi.com", 3478), + ("stun.modulus.gr", 3478), + ("stun.mozcom.com", 3478), + ("stun.myvoiptraffic.com", 3478), + ("stun.mywatson.it", 3478), + ("stun.nas.net", 3478), + ("stun.neotel.co.za", 3478), + ("stun.netappel.com", 3478), + ("stun.netappel.fr", 3478), + ("stun.netgsm.com.tr", 3478), + ("stun.nfon.net", 3478), + ("stun.noblogs.org", 3478), + ("stun.noc.ams-ix.net", 3478), + ("stun.node4.co.uk", 3478), + ("stun.nonoh.net", 3478), + ("stun.nottingham.ac.uk", 3478), + ("stun.nova.is", 3478), + ("stun.nventure.com", 3478), + ("stun.on.net.mk", 3478), + ("stun.ooma.com", 3478), + ("stun.ooonet.ru", 3478), + ("stun.oriontelekom.rs", 3478), + ("stun.outland-net.de", 3478), + ("stun.ozekiphone.com", 3478), + ("stun.patlive.com", 3478), + ("stun.personal-voip.de", 3478), + ("stun.petcube.com", 3478), + ("stun.phone.com", 3478), + ("stun.phoneserve.com", 3478), + ("stun.pjsip.org", 3478), + ("stun.poivy.com", 3478), + ("stun.powerpbx.org", 3478), + ("stun.powervoip.com", 3478), + ("stun.ppdi.com", 3478), + ("stun.prizee.com", 3478), + ("stun.qq.com", 3478), + ("stun.qvod.com", 3478), + ("stun.rackco.com", 3478), + ("stun.rapidnet.de", 3478), + ("stun.rb-net.com", 3478), + ("stun.refint.net", 3478), + ("stun.remote-learner.net", 3478), + ("stun.rixtelecom.se", 3478), + ("stun.rockenstein.de", 3478), + ("stun.rolmail.net", 3478), + ("stun.rounds.com", 3478), + ("stun.rynga.com", 3478), + ("stun.samsungsmartcam.com", 3478), + ("stun.schlund.de", 3478), + ("stun.services.mozilla.com", 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.skylink.ru", 3478), + ("stun.sma.de", 3478), + ("stun.smartvoip.com", 3478), + ("stun.smsdiscount.com", 3478), + ("stun.snafu.de", 3478), + ("stun.softjoys.com", 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.spokn.com", 3478), + ("stun.srce.hr", 3478), + ("stun.ssl7.net", 3478), + ("stun.stunprotocol.org", 3478), + ("stun.symform.com", 3478), + ("stun.symplicity.com", 3478), + ("stun.sysadminman.net", 3478), + ("stun.t-online.de", 3478), + ("stun.tagan.ru", 3478), + ("stun.tatneft.ru", 3478), + ("stun.teachercreated.com", 3478), + ("stun.tel.lu", 3478), + ("stun.telbo.com", 3478), + ("stun.telefacil.com", 3478), + ("stun.tis-dialog.ru", 3478), + ("stun.tng.de", 3478), + ("stun.twt.it", 3478), + ("stun.u-blox.com", 3478), + ("stun.ucallweconn.net", 3478), + ("stun.ucsb.edu", 3478), + ("stun.ucw.cz", 3478), + ("stun.uls.co.za", 3478), + ("stun.unseen.is", 3478), + ("stun.usfamily.net", 3478), + ("stun.veoh.com", 3478), + ("stun.vidyo.com", 3478), + ("stun.vipgroup.net", 3478), + ("stun.virtual-call.com", 3478), + ("stun.viva.gr", 3478), + ("stun.vivox.com", 3478), + ("stun.vline.com", 3478), + ("stun.vo.lu", 3478), + ("stun.vodafone.ro", 3478), + ("stun.voicetrading.com", 3478), + ("stun.voip.aebc.com", 3478), + ("stun.voip.blackberry.com", 3478), + ("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.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.vopium.com", 3478), + ("stun.voxgratia.org", 3478), + ("stun.voxox.com", 3478), + ("stun.voys.nl", 3478), + ("stun.voztele.com", 3478), + ("stun.vyke.com", 3478), + ("stun.webcalldirect.com", 3478), + ("stun.whoi.edu", 3478), + ("stun.wifirst.net", 3478), + ("stun.wwdl.net", 3478), + ("stun.xs4all.nl", 3478), + ("stun.xtratelecom.es", 3478), + ("stun.yesss.at", 3478), + ("stun.zadarma.com", 3478), + ("stun.zadv.com", 3478), + ("stun.zoiper.com", 3478), + ("stun1.faktortel.com.au", 3478), + ("stun1.l.google.com", 19302), + ("stun1.voiceeclipse.net", 3478), + ("stun2.l.google.com", 19302), + ("stun3.l.google.com", 19302), + ("stun4.l.google.com", 19302), + ("stunserver.org", 3478) + }; Console.WriteLine("Contacting STUN servers to obtain your IP"); - foreach (Tuple server in stunServers) + foreach ((string host, int port) in stunServers) { - string host = server.Item1; - int port = server.Item2; - StunResult externalEndPoint = StunClient.Query(host, port, socket); if (externalEndPoint.NetType == StunNetType.UdpBlocked) @@ -476,10 +474,9 @@ static P2pEndPoint GetExternalEndPoint(Socket socket) return null; } - static int SleepTime(DateTime now) { - List seconds = new List() {10, 20, 30, 40, 50, 60}; + List seconds = new List() { 10, 20, 30, 40, 50, 60 }; int next = seconds.Find(x => x > now.Second); @@ -508,8 +505,7 @@ static UdtSocket PeerConnect(Socket socket, string remoteAddr, int remotePort) GetExternalEndPoint(socket); - if (client != null) - client.Close(); + client?.Close(); client = new UdtSocket(socket.AddressFamily, socket.SocketType); client.Bind(socket); diff --git a/SizeConverter.cs b/SizeConverter.cs index fa0c9a9..80caeda 100644 --- a/SizeConverter.cs +++ b/SizeConverter.cs @@ -12,9 +12,9 @@ internal static class SizeConverter { internal static string ConvertToSizeString(long size) { - DataSizeUnit totalSizeUnit = SizeConverter.GetSuitableUnit(size); - return string.Format("{0:#0.##} {1}", SizeConverter.ConvertToSize( - size, totalSizeUnit), SizeConverter.GetUnitString(totalSizeUnit)); + DataSizeUnit totalSizeUnit = GetSuitableUnit(size); + return string.Format("{0:#0.##} {1}", ConvertToSize( + size, totalSizeUnit), GetUnitString(totalSizeUnit)); } internal static float ConvertToSize(long size, DataSizeUnit unit) @@ -24,26 +24,25 @@ internal static float ConvertToSize(long size, DataSizeUnit unit) static string GetUnitString(DataSizeUnit unit) { - switch (unit) + return unit switch { - case DataSizeUnit.Bytes: return "bytes"; - case DataSizeUnit.KiloBytes: return "KB"; - case DataSizeUnit.MegaBytes: return "MB"; - case DataSizeUnit.GigaBytes: return "GB"; - } - return string.Empty; + DataSizeUnit.Bytes => "bytes", + DataSizeUnit.KiloBytes => "KB", + DataSizeUnit.MegaBytes => "MB", + DataSizeUnit.GigaBytes => "GB", + _ => string.Empty, + }; } static DataSizeUnit GetSuitableUnit(long size) { - if (size >= 0 && size < (long)DataSizeUnit.KiloBytes) - return DataSizeUnit.Bytes; - else if (size >= (long)DataSizeUnit.KiloBytes && size <= (long)DataSizeUnit.MegaBytes) - return DataSizeUnit.KiloBytes; - else if (size >= (long)DataSizeUnit.MegaBytes && size <= (long)DataSizeUnit.GigaBytes) - return DataSizeUnit.MegaBytes; - else - return DataSizeUnit.GigaBytes; + return size switch + { + >= 0 and < (long)DataSizeUnit.KiloBytes => DataSizeUnit.Bytes, + >= (long)DataSizeUnit.KiloBytes and <= (long)DataSizeUnit.MegaBytes => DataSizeUnit.KiloBytes, + >= (long)DataSizeUnit.MegaBytes and <= (long)DataSizeUnit.GigaBytes => DataSizeUnit.MegaBytes, + _ => DataSizeUnit.GigaBytes + }; } } } diff --git a/StunClient.cs b/StunClient.cs index 14c5c80..8a57f90 100644 --- a/StunClient.cs +++ b/StunClient.cs @@ -60,7 +60,6 @@ internal STUN_t_ErrorCode(int code, string reasonText) m_ReasonText = reasonText; } - #region Properties Implementation /// @@ -187,14 +186,13 @@ internal StunMessage() m_pTransactionID = Guid.NewGuid(); } - /// /// Parses STUN message from raw data packet. /// /// Raw STUN message. internal void Parse(byte[] data) { - /* RFC 3489 11.1. + /* RFC 3489 11.1. All STUN messages consist of a 20 byte header: 0 1 2 3 @@ -210,7 +208,7 @@ Transaction ID +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - + The message length is the count, in bytes, of the size of the message, not including the 20 byte header. */ @@ -277,7 +275,7 @@ Transaction ID /// Returns raw STUN packet. internal byte[] ToByteData() { - /* RFC 3489 11.1. + /* RFC 3489 11.1. All STUN messages consist of a 20 byte header: 0 1 2 3 @@ -293,7 +291,7 @@ Transaction ID +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - + The message length is the count, in bytes, of the size of the message, not including the 20 byte header. @@ -474,7 +472,7 @@ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | Type | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Value .... - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ // Type @@ -601,7 +599,7 @@ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 /// STUN message data. /// Offset in data. /// Returns parsed IP end point. - IPEndPoint ParseEndPoint(byte[] data, ref int offset) + static IPEndPoint ParseEndPoint(byte[] data, ref int offset) { /* It consists of an eight bit address family, and a sixteen bit @@ -640,7 +638,7 @@ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 /// IP end point. /// Buffer where to store. /// Offset in buffer. - void StoreEndPoint(AttributeType type, IPEndPoint endPoint, byte[] message, ref int offset) + static void StoreEndPoint(AttributeType type, IPEndPoint endPoint, byte[] message, ref int offset) { /* It consists of an eight bit address family, and a sixteen bit @@ -652,7 +650,7 @@ 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |x x x x x x x x| Family | Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ // Header @@ -738,7 +736,7 @@ internal IPEndPoint SourceAddress } /// - /// Gets or sets IP end point where STUN server will send response back to STUN client + /// Gets or sets IP end point where STUN server will send response back to STUN client /// if the "change IP" and "change port" flags had been set in the ChangeRequest. /// internal IPEndPoint ChangedAddress @@ -750,7 +748,7 @@ internal IPEndPoint ChangedAddress /// /// Gets or sets user name. Value null means not specified. - /// + /// internal string UserName { get { return m_UserName; } @@ -780,7 +778,6 @@ internal STUN_t_ErrorCode ErrorCode set { m_pErrorCode = value; } } - /// /// Gets or sets IP endpoint from which IP end point STUN server got STUN client request. /// Value null means not specified. @@ -801,7 +798,7 @@ internal IPEndPoint ReflectedFrom /// // Create new socket for STUN client. /// Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp); /// socket.Bind(new IPEndPoint(IPAddress.Any,0)); - /// + /// /// // Query STUN server /// STUN_Result result = STUN_Client.Query("stunserver.org",3478,socket); /// if(result.NetType != STUN_NetType.UdpBlocked){ @@ -813,7 +810,7 @@ internal IPEndPoint ReflectedFrom /// } /// /// - internal class StunClient + internal static class StunClient { #region static method Query @@ -829,11 +826,11 @@ internal static StunResult Query(string host, int port, Socket socket) { if (host == null) { - throw new ArgumentNullException("host"); + throw new ArgumentNullException(nameof(host)); } if (socket == null) { - throw new ArgumentNullException("socket"); + throw new ArgumentNullException(nameof(socket)); } if (port < 1) { @@ -851,14 +848,14 @@ internal static StunResult Query(string host, int port, Socket socket) /* In test I, the client sends a STUN Binding Request to a server, without any flags set in the - CHANGE-REQUEST attribute, and without the RESPONSE-ADDRESS attribute. This causes the server + CHANGE-REQUEST attribute, and without the RESPONSE-ADDRESS attribute. This causes the server to send the response back to the address and port that the request came from. - + In test II, the client sends a Binding Request with both the "change IP" and "change port" flags - from the CHANGE-REQUEST attribute set. - + from the CHANGE-REQUEST attribute set. + In test III, the client sends a Binding Request with only the "change port" flag set. - + +--------+ | Test | | I | @@ -905,8 +902,10 @@ Symmetric N / \ +--------+ N / \ V */ // Test I - StunMessage test1 = new StunMessage(); - test1.Type = StunMessageType.BindingRequest; + StunMessage test1 = new StunMessage + { + Type = StunMessageType.BindingRequest + }; StunMessage test1response = DoTransaction(test1, socket, remoteEndPoint); // UDP blocked. @@ -917,9 +916,11 @@ Symmetric N / \ +--------+ N / \ V else { // Test II - StunMessage test2 = new StunMessage(); - test2.Type = StunMessageType.BindingRequest; - test2.ChangeRequest = new StunChangeRequest(true, true); + StunMessage test2 = new StunMessage + { + Type = StunMessageType.BindingRequest, + ChangeRequest = new StunChangeRequest(true, true) + }; // No NAT. if (socket.LocalEndPoint.Equals(test1response.MappedAddress)) @@ -948,13 +949,15 @@ Symmetric N / \ +--------+ N / \ V else { /* - If no response is received, it performs test I again, but this time, does so to + If no response is received, it performs test I again, but this time, does so to the address and port from the CHANGED-ADDRESS attribute from the response to test I. */ // Test I(II) - StunMessage test12 = new StunMessage(); - test12.Type = StunMessageType.BindingRequest; + StunMessage test12 = new StunMessage + { + Type = StunMessageType.BindingRequest + }; StunMessage test12Response = DoTransaction(test12, socket, test1response.ChangedAddress); if (test12Response == null) @@ -971,9 +974,11 @@ the address and port from the CHANGED-ADDRESS attribute from the response to tes else { // Test III - StunMessage test3 = new StunMessage(); - test3.Type = StunMessageType.BindingRequest; - test3.ChangeRequest = new StunChangeRequest(false, true); + StunMessage test3 = new StunMessage + { + Type = StunMessageType.BindingRequest, + ChangeRequest = new StunChangeRequest(false, true) + }; StunMessage test3Response = DoTransaction(test3, socket, test1response.ChangedAddress); // Restricted @@ -1044,43 +1049,7 @@ static StunMessage DoTransaction(StunMessage request, Socket socket, IPEndPoint } - internal class StunResult - { - StunNetType m_NetType = StunNetType.OpenInternet; - IPEndPoint m_pPublicEndPoint = null; - - /// - /// Default constructor. - /// - /// Specifies UDP network type. - /// Public IP end point. - internal StunResult(StunNetType netType, IPEndPoint publicEndPoint) - { - m_NetType = netType; - m_pPublicEndPoint = publicEndPoint; - } - - - #region Properties Implementation - - /// - /// Gets UDP network type. - /// - internal StunNetType NetType - { - get { return m_NetType; } - } - - /// - /// Gets internal IP end point. This value is null if failed to get network type. - /// - internal IPEndPoint PublicEndPoint - { - get { return m_pPublicEndPoint; } - } - - #endregion - } + internal record StunResult(StunNetType NetType, IPEndPoint PublicEndPoint); /// /// Specifies UDP network type. @@ -1103,32 +1072,32 @@ internal enum StunNetType SymmetricUdpFirewall, /// - /// A full cone NAT is one where all requests from the same internal IP address and port are - /// mapped to the same external IP address and port. Furthermore, any external host can send + /// A full cone NAT is one where all requests from the same internal IP address and port are + /// mapped to the same external IP address and port. Furthermore, any external host can send /// a packet to the internal host, by sending a packet to the mapped external address. /// FullCone, /// - /// A restricted cone NAT is one where all requests from the same internal IP address and + /// A restricted cone NAT is one where all requests from the same internal IP address and /// port are mapped to the same external IP address and port. Unlike a full cone NAT, an external - /// host (with IP address X) can send a packet to the internal host only if the internal host + /// host (with IP address X) can send a packet to the internal host only if the internal host /// had previously sent a packet to IP address X. /// RestrictedCone, /// - /// A port restricted cone NAT is like a restricted cone NAT, but the restriction + /// A port restricted cone NAT is like a restricted cone NAT, but the restriction /// includes port numbers. Specifically, an external host can send a packet, with source IP - /// address X and source port P, to the internal host only if the internal host had previously + /// address X and source port P, to the internal host only if the internal host had previously /// sent a packet to IP address X and port P. /// PortRestrictedCone, /// - /// A symmetric NAT is one where all requests from the same internal IP address and port, + /// A symmetric NAT is one where all requests from the same internal IP address and port, /// to a specific destination IP address and port, are mapped to the same external IP address and - /// port. If the same host sends a packet with the same source address and port, but to + /// port. If the same host sends a packet with the same source address and port, but to /// a different destination, a different mapping is used. Furthermore, only the external host that /// receives a packet can send a UDP packet back to the internal host. ///