public async Task <bool> CheckUdpHolePunchingAvailable()
        {
            if (!_remoteConnectionInformation.UdpConnectionInformation.IsHolePunchingPossible)
            {
                return(false);
            }

            return(await Task.Run(() =>
            {
                var ipAddress = NetworkUtilities.GetLanIp();
                using (var socket = new Socket(SocketType.Dgram, ProtocolType.Udp))
                {
                    socket.Bind(new IPEndPoint(ipAddress, 3478));

                    IPEndPoint ipEndPoint;

                    if (SessionTraversalUtilitiesForNAT.IsHolePunchingPossible(socket, out ipEndPoint))
                    {
                        return true;
                    }

                    socket.Close();
                }

                return false;
            }));
        }
Example #2
0
        public ConfigureServerViewModel()
        {
            IpAddresses = new ObservableCollection <IpAddressInfo>();

            var ipAddresses = Dns.GetHostAddresses(Dns.GetHostName())
                              .OrderByDescending(x => x.AddressFamily == AddressFamily.InterNetwork)
                              .Select(x => x.ToString())
                              .ToList();

            ipAddresses.Insert(0, "127.0.0.1");
            AvailableIpAddresses = ipAddresses.ToArray();

            IpAddresses.Add(new IpAddressInfo {
                Ip = "127.0.0.1", Port = 10134
            });
            IpAddresses.Add(new IpAddressInfo {
                Ip = NetworkUtilities.GetLanIp().ToString(), Port = 10134
            });
        }
        public RemoteConnectionInformation GetCoreInformation(ConnectionProtocol connectionProtocol)
        {
            var information = new RemoteConnectionInformation {
                LocalIpAddress = NetworkUtilities.GetLanIp()
            };

            if ((connectionProtocol & ConnectionProtocol.Tcp) == ConnectionProtocol.Tcp)
            {
                //nothing available currently
            }

            if ((connectionProtocol & ConnectionProtocol.Udp) == ConnectionProtocol.Udp)
            {
                information.UdpConnectionInformation = new UdpConnectionInformation();

                try
                {
                    var ipAddress = NetworkUtilities.GetLanIp();
                    var socket    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    socket.Bind(new IPEndPoint(ipAddress, 3478));

                    IPEndPoint ipEndPoint;

                    if (SessionTraversalUtilitiesForNAT.IsHolePunchingPossible(socket, out ipEndPoint))
                    {
                        information.UdpConnectionInformation.IsHolePunchingPossible = true;
                    }
                    socket.Close();
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            return(information);
        }
Example #4
0
 public static PhysicalAddress GetDestinationMacAddress(IPAddress address)
 {
     return(GetDestinationMacAddress(address, NetworkUtilities.GetLanIp()));
 }