Example #1
0
        private static bool PIAUp()
        {
            try
            {
                NetworkInterface ni = NetworkInterface.GetAllNetworkInterfaces()[0];

                foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (NI.Description.Contains("TAP-Windows"))
                    {
                        GatewayIPAddressInformationCollection addr = NI.GetIPProperties().GatewayAddresses;
                        if (addr.Count() > 0)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ShowBalloon("Network", e);
            }

            return(false);
        }
Example #2
0
        public static IPAddress GetExternalIPv4ByUnicastAddress()
        {
            // Loop through each network interface in the system
            foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
            {
                // Loop through each gateway address for the current network interface
                IPInterfaceProperties IPIP = NI.GetIPProperties();
                foreach (GatewayIPAddressInformation GIPAddress in IPIP.GatewayAddresses)
                {
                    // Ensure gateway is IPv4, and not IPAddress.ANY or IPAddress.NONE
                    if ((GIPAddress.Address.AddressFamily == AddressFamily.InterNetwork) && (GIPAddress.Address.ToString() != IPAddress.Any.ToString()) && (GIPAddress.Address.ToString() != IPAddress.None.ToString()))
                    {
                        // Gateway is valid, so loop through each unicast address for the current network interface
                        foreach (UnicastIPAddressInformation UIPAddress in NI.GetIPProperties().UnicastAddresses)
                        {
                            // Ensure unicast address is IPv4, and not IPAddress.ANY or IPAddress.NONE
                            if ((UIPAddress.Address.AddressFamily == AddressFamily.InterNetwork) && (UIPAddress.Address.ToString() != IPAddress.Any.ToString()) && (UIPAddress.Address.ToString() != IPAddress.None.ToString()))
                            {
                                if (!IsPrivateIP(UIPAddress.Address))
                                {
                                    return(UIPAddress.Address);
                                }
                            }
                        }
                        break;
                    }
                }
            }

            return(IPAddress.None);
        }
        private void CardsList()
        {
            Dictionary <string, IPAddress> cmdSource = new Dictionary <string, IPAddress>();

            foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
            {
                foreach (UnicastIPAddressInformation IP in NI.GetIPProperties().UnicastAddresses)
                {
                    if (IP.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        cmdSource.Add(IP.Address.ToString() + " - " + NI.Description, IP.Address);
                    }
                }
            }
            ComeAdapterCmbBox.DataSource    = new BindingSource(cmdSource, null);
            ComeAdapterCmbBox.DisplayMember = "Key";
            ComeAdapterCmbBox.ValueMember   = "Value";
        }
        void KartlariListele()
        {
            Dictionary <string, IPAddress> cmbKaynak = new Dictionary <string, IPAddress>();

            foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
            {
                foreach (UnicastIPAddressInformation IP in NI.GetIPProperties().UnicastAddresses)
                {
                    if (IP.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        cmbKaynak.Add(IP.Address.ToString() + " - " + NI.Description, IP.Address);
                    }
                }
            }

            cmbNetworks.DataSource    = new BindingSource(cmbKaynak, null);
            cmbNetworks.DisplayMember = "Key";
            cmbNetworks.ValueMember   = "Value";
        }
Example #5
0
 private void getAdapterAddress()
 {
     this._wifiIP = String.Empty;
     this._lanIP  = String.Empty;
     foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
     {
         if (NI.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
         {
             foreach (UnicastIPAddressInformation IP in NI.GetIPProperties().UnicastAddresses)
             {
                 if (IP.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && IP.IsDnsEligible && !NI.Description.Contains("Virtual"))
                 {
                     this._wifiIP = IP.Address.ToString();
                     break;
                 }
             }
         }
         else if (NI.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
         {
             foreach (UnicastIPAddressInformation IP in NI.GetIPProperties().UnicastAddresses)
             {
                 if (IP.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && IP.IsDnsEligible && !NI.Description.Contains("Virtual"))
                 {
                     //USB Wireless Network Adapter Will be Here
                     if (NI.Description.Contains("Wireless") && NI.Description.Contains("802.11"))
                     {
                         this._wifiIP = IP.Address.ToString();
                     }
                     else
                     {
                         this._lanIP = IP.Address.ToString();
                         break;
                     }
                 }
             }
         }
     }
     if (this._wifiIP.Length > 0 || this._lanIP.Length > 0)
     {
         this.printJSLog("IP Address " + (this._wifiIP.Length > 0?" WIFI:" + this._wifiIP:"") + (this._lanIP.Length > 0?"  Ethernet:" + this._lanIP:""));
     }
 }
        /// <summary>
        /// Combobox Doldur
        /// </summary>
        public static void ComboBoxFill(ComboBox comboBox)
        {
            //Aktif IP adresleri bulunup combobox a ekleniyor.
            Dictionary <string, IPAddress> comboFill = new Dictionary <string, IPAddress>();

            foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
            {
                foreach (UnicastIPAddressInformation IP in NI.GetIPProperties().UnicastAddresses)
                {
                    if (IP.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        comboFill.Add(IP.Address.ToString() + " - " + NI.Description, IP.Address);
                    }
                }
            }

            comboBox.DataSource    = new BindingSource(comboFill, null);
            comboBox.DisplayMember = "Key";
            comboBox.ValueMember   = "Value";
        }
Example #7
0
        static private List <UdpClient> GetUdpClients()
        {
            List <UdpClient> Result = new List <UdpClient>();

            try
            {
                // Loop through each network interface in the system
                foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
                {
                    // Loop through each gateway address for the current network interface
                    IPInterfaceProperties IPIP = NI.GetIPProperties();
                    foreach (GatewayIPAddressInformation GIPAddress in IPIP.GatewayAddresses)
                    {
                        // Ensure gateway is IPv4, and not IPAddress.ANY or IPAddress.NONE
                        if ((GIPAddress.Address.AddressFamily == AddressFamily.InterNetwork) && (GIPAddress.Address.ToString() != IPAddress.Any.ToString()) && (GIPAddress.Address.ToString() != IPAddress.None.ToString()))
                        {
                            // Gateway is valid, so add new UdpClient
                            try
                            {
                                UdpClient  Client         = new UdpClient();
                                IPEndPoint RemoteEndPoint = new IPEndPoint(GIPAddress.Address, 5351);
                                Client.Connect(RemoteEndPoint);
                                Result.Add(Client);
                            }
                            catch
                            {
                                // Ignore, don't want a single gateway failure to abort all gateway lookups
                            }
                            break;
                        }
                    }
                }
            }
            catch
            {
                // Ignore, indicates windows system call failure
            }

            return(Result);
        }
Example #8
0
    public static void Main()
    {
        string _wifiIP = String.Empty;
        string _lanIP  = String.Empty;

        foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (NI.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
            {
                foreach (UnicastIPAddressInformation IP in NI.GetIPProperties().UnicastAddresses)
                {
                    if (IP.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && IP.IsDnsEligible && !NI.Description.Contains("Virtual"))
                    {
                        _wifiIP = IP.Address.ToString();
                        break;
                    }
                }
            }
            else if (NI.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
            {
                foreach (UnicastIPAddressInformation IP in NI.GetIPProperties().UnicastAddresses)
                {
                    if (IP.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && IP.IsDnsEligible && !NI.Description.Contains("Virtual"))
                    {
                        //USB NetWork Adapter will Here
                        if (NI.Description.Contains("Wireless") && NI.Description.Contains("802."))
                        {
                            _wifiIP = IP.Address.ToString();
                        }
                        else
                        {
                            _lanIP = IP.Address.ToString();
                            break;
                        }
                    }
                }
            }
        }
        System.Console.WriteLine("\nNetwork Adapter Addresses : " + _wifiIP + " " + _lanIP + "\n");
    }
Example #9
0
        static private List <UdpClient> GetUdpClients()
        {
            List <UdpClient> Result = new List <UdpClient>();

            // Loop through each network interface in the system
            foreach (NetworkInterface NI in NetworkInterface.GetAllNetworkInterfaces())
            {
                // Loop through each gateway address for the current network interface
                IPInterfaceProperties IPIP = NI.GetIPProperties();
                foreach (GatewayIPAddressInformation GIPAddress in IPIP.GatewayAddresses)
                {
                    // Ensure gateway is IPv4, and not IPAddress.ANY or IPAddress.NONE
                    if ((GIPAddress.Address.AddressFamily == AddressFamily.InterNetwork) && (GIPAddress.Address.ToString() != IPAddress.Any.ToString()) && (GIPAddress.Address.ToString() != IPAddress.None.ToString()))
                    {
                        // Gateway is valid, so loop through each unicast address for the current network interface
                        foreach (UnicastIPAddressInformation UIPAddress in NI.GetIPProperties().UnicastAddresses)
                        {
                            // Ensure unicast address is IPv4, and not IPAddress.ANY or IPAddress.NONE
                            if ((UIPAddress.Address.AddressFamily == AddressFamily.InterNetwork) && (UIPAddress.Address.ToString() != IPAddress.Any.ToString()) && (UIPAddress.Address.ToString() != IPAddress.None.ToString()))
                            {
                                try
                                {
                                    Result.Add(new UdpClient(new IPEndPoint(UIPAddress.Address, 0)));
                                }
                                catch
                                {
                                    // Ignore
                                }
                            }
                        }
                        break;
                    }
                }
            }

            return(Result);
        }
Example #10
0
        /// <summary>
        /// Create a new DNS resolver client.
        /// </summary>
        /// <param name="ManualDNSServers">A list of manually configured DNS servers to query.</param>
        /// <param name="SearchForIPv4DNSServers">If yes, the DNS client will query a list of DNS servers from the IPv4 network configuration.</param>
        /// <param name="SearchForIPv6DNSServers">If yes, the DNS client will query a list of DNS servers from the IPv6 network configuration.</param>
        public DNSClient(IEnumerable <IPSocket> ManualDNSServers,
                         Boolean SearchForIPv4DNSServers = true,
                         Boolean SearchForIPv6DNSServers = true)

        {
            this._DNSCache        = new DNSCache();
            this.RecursionDesired = true;
            this.QueryTimeout     = TimeSpan.FromSeconds(23.5);

            _DNSServers = new List <IPSocket>(ManualDNSServers);

            #region Search for IPv4/IPv6 DNS Servers...

            if (SearchForIPv4DNSServers)
            {
                _DNSServers.AddRange(NetworkInterface.
                                     GetAllNetworkInterfaces().
                                     Where(NI => NI.OperationalStatus == OperationalStatus.Up).
                                     SelectMany(NI => NI.GetIPProperties().DnsAddresses).
                                     Where(IPAddress => IPAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).
                                     Select(IPAddress => new IPSocket(new IPv4Address(IPAddress), new IPPort(53))));
            }

            if (SearchForIPv6DNSServers)
            {
                _DNSServers.AddRange(NetworkInterface.
                                     GetAllNetworkInterfaces().
                                     Where(NI => NI.OperationalStatus == OperationalStatus.Up).
                                     SelectMany(NI => NI.GetIPProperties().DnsAddresses).
                                     Where(IPAddress => IPAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6).
                                     Select(IPAddress => new IPSocket(new IPv6Address(IPAddress), new IPPort(53))));
            }

            #endregion

            #region Reflect ResourceRecordTypes

            this._RRLookup = new Dictionary <UInt16, ConstructorInfo>();

            FieldInfo       TypeIdField;
            ConstructorInfo Constructor;

            foreach (var _ActualType in typeof(ADNSResourceRecord).
                     Assembly.GetTypes().
                     Where(type => type.IsClass &&
                           !type.IsAbstract &&
                           type.IsSubclassOf(typeof(ADNSResourceRecord))))
            {
                TypeIdField = _ActualType.GetField("TypeId");

                if (TypeIdField == null)
                {
                    throw new ArgumentException("Constant field 'TypeId' of type '" + _ActualType.Name + "' was not found!");
                }

                Constructor = _ActualType.GetConstructor(new Type[2] {
                    typeof(String), typeof(Stream)
                });

                if (Constructor == null)
                {
                    throw new ArgumentException("Constructor<String, Stream> of type '" + _ActualType.Name + "' was not found!");
                }

                _RRLookup.Add((UInt16)TypeIdField.GetValue(_ActualType), Constructor);
            }

            #endregion
        }