Ejemplo n.º 1
0
    public void Connect()
    {
        clients.Clear();
        lastContactWithClient.Clear();
        clientGuids.Clear();
        toDos.Clear();

        IPEndPoint stunEndPoint = new IPEndPoint(IPAddress.Any, 0);

        foreach (IPAddress ip in Dns.GetHostAddresses("stun3.l.google.com"))
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                stunEndPoint = new IPEndPoint(ip, 19302);
            }
        }

        if (stunEndPoint.Address == IPAddress.Any)
        {
            throw new Exception("STUN failed");
        }

        socket.Bind(new IPEndPoint(IPAddress.Any, port));
        Debug.Log("[Server][" + DateTime.Now + "] START " + socket.LocalEndPoint);

        STUNQueryResult queryResult = STUNClient.Query(socket, stunEndPoint, STUNQueryType.PublicIP);

        publicEndPoint = queryResult.PublicEndPoint;

        Debug.Log("[Server][" + DateTime.Now + "] STUN " + publicEndPoint + " via STUN server " + stunEndPoint);
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (!STUNUtils.TryParseHostAndPort("stun.schlund.de:3478", out IPEndPoint stunEndPoint))
            {
                throw new Exception("Failed to resolve STUN server address");
            }

            STUNClient.ReceiveTimeout = 500;
            STUNQueryFullResult queryResult;

            try
            {
                queryResult = STUNClient.TryQuery(stunEndPoint, STUNQueryType.ExactNAT, true, NATTypeDetectionRFC.Rfc5780);
            }
            catch (STUNQueryErrorException ex)
            {
                throw new Exception("Query Error: " + ex.Error.ToString());
            }
            catch (STUNServerErrorException ex)
            {
                throw new Exception($"Server Error ({ex.ErrorCode}): {ex.ErrorPhrase}");
            }

            Console.WriteLine("PublicEndPoint: {0}", queryResult.PublicEndPoint);
            Console.WriteLine("LocalEndPoint: {0}", queryResult.LocalEndPoint);
            Console.WriteLine("NAT Type: {0}", queryResult.NATType);
        }
Ejemplo n.º 3
0
        public void Init()
        {
            var port = FreePort.FindNextAvailableUDPPort(15090);

            transport       = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine());
            publicIPAddress = STUNClient.GetPublicIPAddress("stun.ekiga.net");
            localIPEndPoint = IpAddressLookup.QueryRoutingInterface(asterisk, port);

            var endpoint = new IPEndPoint(localIPEndPoint.Address, port);
            var channel  = new SIPUDPChannel(endpoint);

            transport.AddSIPChannel(channel);
            transport.SIPTransportRequestReceived += Transport_SIPTransportRequestReceived;

            //var registration = new SIPRegistrationUserAgent(
            //        transport,
            //        null,
            //        new SIPEndPoint(SIPProtocolsEnum.udp, publicIPAddress, port),
            //        new SIPURI("1003", asterisk, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
            //        "1003",
            //        passwords[0],
            //        null,
            //        asterisk,
            //        new SIPURI(SIPSchemesEnum.sip, new SIPEndPoint(SIPProtocolsEnum.udp, publicIPAddress, port)),
            //        180,
            //        null,
            //        null,
            //        (e) => { logger.Debug($"{ prefix } SIPRegistrationUserAgent; { e.Message }"); }
            //    );

            //registration.RegistrationSuccessful += Registration_RegistrationSuccessful;
            //registration.RegistrationFailed     += Registration_RegistrationFailed;
            //registration.Start();
        }
Ejemplo n.º 4
0
        public void GetPublicIPStunClientTestMethod()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var publicIP = STUNClient.GetPublicIPAddress("stun.sipsorcery.com");

            logger.LogDebug($"Public IP address {publicIP}.");
        }
Ejemplo n.º 5
0
        public static STUNQueryResult DoSTUN(Socket sock)
        {
            string[] stunhosts = { "stun.l.google.com:19302", "galvinism.ink:3478" };

            foreach (var stunhost in stunhosts)
            {
                try
                {
                    var       ihe      = Dns.GetHostEntry(stunhost.Split(":")[0]);
                    IPAddress targetip = null;
                    foreach (IPAddress ip in ihe.AddressList)
                    {
                        if (ip.AddressFamily == AddressFamily.InterNetwork)
                        {
                            targetip = ip;
                        }
                    }

                    IPEndPoint stunEndPoint = new IPEndPoint(targetip, int.Parse(stunhost.Split(":")[1]));

//                    if (!STUNUtils.TryParseHostAndPort(stunhost, out var stunEndPoint))
//                        throw new Exception("Failed to resolve STUN server address");

                    STUNClient.ReceiveTimeout = 500;
                    var queryResult = STUNClient.Query(sock, stunEndPoint, STUNQueryType.ExactNAT,
                                                       NATTypeDetectionRFC.Rfc3489);

                    if (queryResult.QueryError != STUNQueryError.Success)
                    {
                        throw new Exception("Query Error: " + queryResult.QueryError);
                    }


                    Debug(string.Format("PublicEndPoint: {0}", queryResult.PublicEndPoint));
                    Debug(string.Format("LocalEndPoint: {0}", queryResult.LocalEndPoint));
                    Debug(string.Format("NAT Type: {0}", queryResult.NATType));

                    return(queryResult);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Could not contact STUN host " + stunhost + " " + e.Message);
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
        private void StartSTUNClient()
        {
            try
            {
                Thread.CurrentThread.Name = STUN_CLIENT_THREAD_NAME;

                logger.Debug("SIPProxyDaemon STUN client started.");

                while (!m_stop)
                {
                    try
                    {
                        IPAddress publicIP = STUNClient.GetPublicIPAddress(m_stunServerHostname);
                        if (publicIP != null)
                        {
                            //logger.Debug("The STUN client was able to determine the public IP address as " + publicIP.ToString() + ".");
                            m_statelessProxyCore.PublicIPAddress = publicIP;
                        }
                        else
                        {
                            // logger.Debug("The STUN client could not determine the public IP address.");
                            m_statelessProxyCore.PublicIPAddress = null;
                        }

                        if (PublicIPAddressUpdated != null)
                        {
                            PublicIPAddressUpdated(publicIP);
                        }
                    }
                    catch (Exception getAddrExcp)
                    {
                        logger.Error("Exception StartSTUNClient GetPublicIPAddress. " + getAddrExcp.Message);
                    }

                    m_stunClientMRE.Reset();
                    m_stunClientMRE.WaitOne(60000);
                }

                logger.Warn("SIPProxyDaemon STUN client thread stopped.");
            }
            catch (Exception excp)
            {
                logger.Error("Exception StartSTUNClient. " + excp.Message);
            }
        }
Ejemplo n.º 7
0
        public void Init()
        {
            var port = FreePort.FindNextAvailableUDPPort(15090);

            transport       = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine());
            publicIPAddress = STUNClient.GetPublicIPAddress("stun.ekiga.net");
            localIPEndPoint = IpAddressLookup.QueryRoutingInterface(asterisk, port);

            var endpoint = new IPEndPoint(localIPEndPoint.Address, port);
            var channel  = new SIPUDPChannel(endpoint);

            //channel.SIPMessageReceived += (SIPChannel sipChannel, SIPEndPoint remoteEndPoint, byte[] buffer) => { logger.Debug("Channel SIP message received " + channel.SIPChannelEndPoint + "<-" + remoteEndPoint); };

            transport.AddSIPChannel(channel);

            for (var i = 0; i < numbers.Length; i++)
            {
                var number       = numbers[i];
                var password     = passwords[i];
                var registration = new SIPRegistrationUserAgent(
                    transport,
                    null,
                    new SIPEndPoint(SIPProtocolsEnum.udp, publicIPAddress, port),
                    new SIPURI(number, asterisk, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp),
                    number,
                    password,
                    null,
                    asterisk,
                    new SIPURI(SIPSchemesEnum.sip, new SIPEndPoint(SIPProtocolsEnum.udp, publicIPAddress, port)),
                    180,
                    null,
                    null,
                    (e) => { logger.Debug(e.Message); }
                    );

                logger.Debug($"{prefix} Registration attempt for {number}@{endpoint.Address}:{endpoint.Port}");

                registration.RegistrationSuccessful += Registration_RegistrationSuccessful;
                registration.RegistrationFailed     += Registration_RegistrationFailed;
                registration.Start();

                registrations.Add(registration);
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            if (!STUNUtils.TryParseHostAndPort("stun.schlund.de:3478", out IPEndPoint stunEndPoint))
            {
                throw new Exception("Failed to resolve STUN server address");
            }

            STUNClient.ReceiveTimeout = 500;
            var queryResult = STUNClient.Query(stunEndPoint, STUNQueryType.ExactNAT, true, NATTypeDetectionRFC.Rfc5780);

            if (queryResult.QueryError != STUNQueryError.Success)
            {
                throw new Exception("Query Error: " + queryResult.QueryError.ToString());
            }

            Console.WriteLine("PublicEndPoint: {0}", queryResult.PublicEndPoint);
            Console.WriteLine("LocalEndPoint: {0}", queryResult.LocalEndPoint);
            Console.WriteLine("NAT Type: {0}", queryResult.NATType);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            if (!STUNClient.TryParseHostAndPort("stun3.l.google.com:19302", out IPEndPoint stunEndPoint))
            {
                throw new Exception("Failed to resolve STUN server address");
            }

            var queryResult = STUNClient.Query(stunEndPoint, STUNQueryType.ExactNAT, false);

            if (queryResult.QueryError != STUNQueryError.Success)
            {
                throw new Exception("Query Error: " + queryResult.QueryError.ToString());
            }

            Console.WriteLine("PublicEndPoint: {0}", queryResult.PublicEndPoint);
            Console.WriteLine("LocalEndPoint: {0}", queryResult.LocalEndPoint);
            Console.WriteLine("NAT Type: {0}", queryResult.NATType);
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            // STUNUtils.TryParseHostAndPort("stun.l.google.com", out IPEndPoint stunEndPoint);
            var address = Dns.GetHostAddresses("stun.l.google.com");
            var stunep  = new IPEndPoint(address[0], 19302);


            var stunResult = STUNClient.Query(stunep, STUNQueryType.ExactNAT, true);

            Console.WriteLine($"loaclEp: {stunResult.LocalEndPoint}");
            Console.WriteLine($"publicEp: {stunResult.PublicEndPoint}");

            var udpClient = new UdpClient(stunResult.LocalEndPoint);

            var ipBytes    = stunResult.PublicEndPoint.Address.GetAddressBytes();
            var portBytes  = BitConverter.GetBytes(((UInt16)(stunResult.PublicEndPoint.Port)));
            var magicToken = new byte[ipBytes.Length + portBytes.Length];

            ipBytes.CopyTo(magicToken, 0);
            portBytes.CopyTo(magicToken, ipBytes.Length);

            Console.WriteLine($"Muj magicToken: {Convert.ToBase64String(magicToken)}");


            var th = new Thread(Receive);

            th.Start(udpClient);
            keepAlive.Start(udpClient);



            while (true)
            {
                var cmd = Console.ReadLine();
                if (cmd.StartsWith("/a"))
                {
                    Console.WriteLine("Remote magicToken:");
                    magicToken = Convert.FromBase64String(Console.ReadLine());

                    var remoteEp = new IPEndPoint(new IPAddress(
                                                      magicToken[0..^ 2]),
Ejemplo n.º 11
0
        private IPAddress GetPublicIPAddress()
        {
            try
            {
                var publicIP = STUNClient.GetPublicIPAddress(m_stunServerHostname);
                if (publicIP != null)
                {
                    logger.Debug($"The STUN client was able to determine the public IP address as {publicIP}");
                }
                else
                {
                    logger.Debug("The STUN client could not determine the public IP address.");
                }

                return(publicIP);
            }
            catch (Exception getAddrExcp)
            {
                logger.Error("Exception GetPublicIPAddress. " + getAddrExcp.Message);
                return(null);
            }
        }
Ejemplo n.º 12
0
        public STUNQueryResult GetAddress()
        {
            var stunServer = "stun.deltamediaplayer.com:3478";

            if (!STUNUtils.TryParseHostAndPort(stunServer, out IPEndPoint stunEndPoint))
            {
                throw new Exception("Failed to resolve STUN server address");
            }

            STUNClient.ReceiveTimeout = 500;
            var queryResult = STUNClient.Query(stunEndPoint, STUNQueryType.PublicIP, true);

            if (queryResult.QueryError != STUNQueryError.Success)
            {
                throw new Exception("Query Error: " + queryResult.QueryError.ToString());
            }

            Console.WriteLine("STUN: PublicEndPoint: {0}", queryResult.PublicEndPoint);
            Console.WriteLine("STUN: LocalEndPoint: {0}", queryResult.LocalEndPoint);

            return(queryResult);
        }
Ejemplo n.º 13
0
        static P2pEndPoint GetExternalEndPoint(Socket socket)
        {
            // https://gist.github.com/zziuni/3741933

            List <Tuple <string, int> > stunServers = new List <Tuple <string, int> >();

            stunServers.Add(new Tuple <string, int>("stun.l.google.com", 19302));
            stunServers.Add(new Tuple <string, int>("iphone-stun.strato-iphone.de", 3478));
            stunServers.Add(new Tuple <string, int>("numb.viagenie.ca", 3478));
            stunServers.Add(new Tuple <string, int>("s1.taraba.net", 3478));
            stunServers.Add(new Tuple <string, int>("s2.taraba.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.12connect.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.12voip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.1und1.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.2talk.co.nz", 3478));
            stunServers.Add(new Tuple <string, int>("stun.2talk.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.3clogic.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.3cx.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.a-mm.tv", 3478));
            stunServers.Add(new Tuple <string, int>("stun.aa.net.uk", 3478));
            stunServers.Add(new Tuple <string, int>("stun.acrobits.cz", 3478));
            stunServers.Add(new Tuple <string, int>("stun.actionvoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.advfn.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.aeta-audio.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.aeta.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.alltel.com.au", 3478));
            stunServers.Add(new Tuple <string, int>("stun.altar.com.pl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.annatel.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.antisip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.arbuz.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.avigora.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.avigora.fr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.awa-shima.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.awt.be", 3478));
            stunServers.Add(new Tuple <string, int>("stun.b2b2c.ca", 3478));
            stunServers.Add(new Tuple <string, int>("stun.bahnhof.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.barracuda.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.bluesip.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.bmwgs.cz", 3478));
            stunServers.Add(new Tuple <string, int>("stun.botonakis.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.budgetphone.nl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.budgetsip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.cablenet-as.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.callromania.ro", 3478));
            stunServers.Add(new Tuple <string, int>("stun.callwithus.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.cbsys.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.chathelp.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.cheapvoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ciktel.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.cloopen.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.colouredlines.com.au", 3478));
            stunServers.Add(new Tuple <string, int>("stun.comfi.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.commpeak.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.comtube.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.comtube.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.cope.es", 3478));
            stunServers.Add(new Tuple <string, int>("stun.counterpath.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.counterpath.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.cryptonit.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.darioflaccovio.it", 3478));
            stunServers.Add(new Tuple <string, int>("stun.datamanagement.it", 3478));
            stunServers.Add(new Tuple <string, int>("stun.dcalling.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.decanet.fr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.demos.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.develz.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.dingaling.ca", 3478));
            stunServers.Add(new Tuple <string, int>("stun.doublerobotics.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.drogon.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.duocom.es", 3478));
            stunServers.Add(new Tuple <string, int>("stun.dus.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.e-fon.ch", 3478));
            stunServers.Add(new Tuple <string, int>("stun.easybell.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.easycall.pl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.easyvoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.efficace-factory.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.einsundeins.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.einsundeins.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ekiga.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.epygi.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.etoilediese.fr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.eyeball.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.faktortel.com.au", 3478));
            stunServers.Add(new Tuple <string, int>("stun.freecall.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.freeswitch.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.freevoipdeal.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.fuzemeeting.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.gmx.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.gmx.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.gradwell.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.halonet.pl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.hellonanu.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.hoiio.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.hosteurope.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ideasip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.imesh.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.infra.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.internetcalls.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.intervoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ipcomms.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ipfire.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ippi.fr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ipshka.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.iptel.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.irian.at", 3478));
            stunServers.Add(new Tuple <string, int>("stun.it1.hr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ivao.aero", 3478));
            stunServers.Add(new Tuple <string, int>("stun.jappix.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.jumblo.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.justvoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.kanet.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.kiwilink.co.nz", 3478));
            stunServers.Add(new Tuple <string, int>("stun.kundenserver.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.linea7.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.linphone.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.liveo.fr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.lowratevoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.lugosoft.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.lundimatin.fr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.magnet.ie", 3478));
            stunServers.Add(new Tuple <string, int>("stun.manle.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.mgn.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.mit.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.mitake.com.tw", 3478));
            stunServers.Add(new Tuple <string, int>("stun.miwifi.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.modulus.gr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.mozcom.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.myvoiptraffic.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.mywatson.it", 3478));
            stunServers.Add(new Tuple <string, int>("stun.nas.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.neotel.co.za", 3478));
            stunServers.Add(new Tuple <string, int>("stun.netappel.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.netappel.fr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.netgsm.com.tr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.nfon.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.noblogs.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.noc.ams-ix.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.node4.co.uk", 3478));
            stunServers.Add(new Tuple <string, int>("stun.nonoh.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.nottingham.ac.uk", 3478));
            stunServers.Add(new Tuple <string, int>("stun.nova.is", 3478));
            stunServers.Add(new Tuple <string, int>("stun.nventure.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.on.net.mk", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ooma.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ooonet.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.oriontelekom.rs", 3478));
            stunServers.Add(new Tuple <string, int>("stun.outland-net.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ozekiphone.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.patlive.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.personal-voip.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.petcube.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.phone.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.phoneserve.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.pjsip.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.poivy.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.powerpbx.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.powervoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ppdi.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.prizee.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.qq.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.qvod.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rackco.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rapidnet.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rb-net.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.refint.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.remote-learner.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rixtelecom.se", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rockenstein.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rolmail.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rounds.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.rynga.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.samsungsmartcam.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.schlund.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.services.mozilla.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sigmavoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sip.us", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sipdiscount.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sipgate.net", 10000));
            stunServers.Add(new Tuple <string, int>("stun.sipgate.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.siplogin.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sipnet.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sipnet.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.siportal.it", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sippeer.dk", 3478));
            stunServers.Add(new Tuple <string, int>("stun.siptraffic.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.skylink.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sma.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.smartvoip.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.smsdiscount.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.snafu.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.softjoys.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.solcon.nl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.solnet.ch", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sonetel.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sonetel.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sovtest.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.speedy.com.ar", 3478));
            stunServers.Add(new Tuple <string, int>("stun.spokn.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.srce.hr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ssl7.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.stunprotocol.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.symform.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.symplicity.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.sysadminman.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.t-online.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.tagan.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.tatneft.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.teachercreated.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.tel.lu", 3478));
            stunServers.Add(new Tuple <string, int>("stun.telbo.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.telefacil.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.tis-dialog.ru", 3478));
            stunServers.Add(new Tuple <string, int>("stun.tng.de", 3478));
            stunServers.Add(new Tuple <string, int>("stun.twt.it", 3478));
            stunServers.Add(new Tuple <string, int>("stun.u-blox.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ucallweconn.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ucsb.edu", 3478));
            stunServers.Add(new Tuple <string, int>("stun.ucw.cz", 3478));
            stunServers.Add(new Tuple <string, int>("stun.uls.co.za", 3478));
            stunServers.Add(new Tuple <string, int>("stun.unseen.is", 3478));
            stunServers.Add(new Tuple <string, int>("stun.usfamily.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.veoh.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vidyo.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vipgroup.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.virtual-call.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.viva.gr", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vivox.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vline.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vo.lu", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vodafone.ro", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voicetrading.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voip.aebc.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voip.blackberry.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voip.eutelia.it", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voiparound.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipblast.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipbuster.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipbusterpro.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipcheap.co.uk", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipcheap.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipfibre.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipgain.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipgate.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipinfocenter.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipplanet.nl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voippro.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipraider.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipstunt.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipwise.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voipzoom.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vopium.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voxgratia.org", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voxox.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voys.nl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.voztele.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.vyke.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.webcalldirect.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.whoi.edu", 3478));
            stunServers.Add(new Tuple <string, int>("stun.wifirst.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.wwdl.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun.xs4all.nl", 3478));
            stunServers.Add(new Tuple <string, int>("stun.xtratelecom.es", 3478));
            stunServers.Add(new Tuple <string, int>("stun.yesss.at", 3478));
            stunServers.Add(new Tuple <string, int>("stun.zadarma.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.zadv.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun.zoiper.com", 3478));
            stunServers.Add(new Tuple <string, int>("stun1.faktortel.com.au", 3478));
            stunServers.Add(new Tuple <string, int>("stun1.l.google.com", 19302));
            stunServers.Add(new Tuple <string, int>("stun1.voiceeclipse.net", 3478));
            stunServers.Add(new Tuple <string, int>("stun2.l.google.com", 19302));
            stunServers.Add(new Tuple <string, int>("stun3.l.google.com", 19302));
            stunServers.Add(new Tuple <string, int>("stun4.l.google.com", 19302));
            stunServers.Add(new Tuple <string, int>("stunserver.org", 3478));

            Console.WriteLine("Contacting STUN servers to obtain your IP");
            foreach (Tuple <string, int> server in stunServers)
            {
                string host = server.Item1;
                int    port = server.Item2;

                if (!STUNUtils.TryParseHostAndPort($"{host}:{port}", out IPEndPoint stunEndPoint))
                {
                    continue;
                }

                STUNQueryResult stunResult = STUNClient.Query(socket, stunEndPoint, STUNQueryType.ExactNAT, NATTypeDetectionRFC.Rfc3489);

                if (stunResult.QueryError != STUNQueryError.Success)
                {
                    continue;
                }

                Console.WriteLine("Your firewall is {0}", stunResult.NATType);

                return(new P2pEndPoint()
                {
                    External = stunResult.PublicEndPoint,
                    Internal = socket.LocalEndPoint as IPEndPoint
                });
            }

            Console.WriteLine("Could not find a working STUN server");
            return(null);
        }