コード例 #1
0
ファイル: ConfigForm.cs プロジェクト: aliakbari/SyslogServer
        public ConfigForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            txtPort.Text = Port.ToString();

            // Populate list of IP addresses
            IPAddress[] localAddresses = LocalIPAddresses.AllAddresses();
            if (localAddresses != null)
            {
                foreach (IPAddress ip in localAddresses)
                {
                    comInterfaces.Items.Add(ip);
                    if (ip == SpecificIP)
                    {
                        comInterfaces.SelectedItem = ip;
                    }
                }

                if (comInterfaces.SelectedItem == null && (comInterfaces.Items.Count > 0))
                {
                    comInterfaces.SelectedItem = comInterfaces.Items[0];
                }
            }

            radListenAll.Checked      = (SpecificIP == null);
            radListenSpecific.Checked = !radListenAll.Checked;

            UpdateGUI();
        }
コード例 #2
0
        [Test] public void LocalIP()
        {
            IPAddress[] addresses = LocalIPAddresses.AllAddresses();

            Assert.IsTrue(addresses != null, "No IP addresses returned");
            Assert.IsTrue(addresses.Length > 0, "No IP addresses found");
        }
コード例 #3
0
ファイル: SIPChannel.cs プロジェクト: mbouchef/sipsorcery
        /// <summary>
        /// Checks whether the host string corresponds to a socket address that this SIP channel is listening on.
        /// </summary>
        /// <param name="host">The host string to check.</param>
        /// <returns>True if the host is a socket this channel is listening on. False if not.</returns>
        internal bool IsChannelSocket(string host)
        {
            if (IPSocket.TryParseIPEndPoint(host, out var ep))
            {
                if (ListeningIPAddress != IPAddress.Any)
                {
                    return(ep.Address.Equals(ListeningIPAddress) && ep.Port == ListeningEndPoint.Port);
                }
                else
                {
                    return(ep.Port == ListeningEndPoint.Port && LocalIPAddresses.Any(x => x.Equals(ep.Address)));
                }
            }

            return(false);
        }
コード例 #4
0
        public static bool IsLocalHost(this string hostName)
        {
            if (string.IsNullOrWhiteSpace(hostName))
            {
                throw new Exception("Missing hostname");
            }

            try
            {
                var IPs = System.Net.Dns.GetHostAddresses(hostName);

                if (IPs == null || IPs.Length < 1)
                {
                    throw new Exception("Could not resolve host name '" + hostName + "'");
                }
                foreach (var address in IPs)
                {
                    if (address.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        continue;
                    }
                    if (address.ToString().EqualsI("127.0.0.1"))
                    {
                        return(true);
                    }
                    if (LocalIPAddresses.ContainsI(address.ToString()))
                    {
                        return(true);
                    }
                }
            }
            catch
            {
            }
            return(false);
        }