/// <summary>
        ///     执行跳转功能
        /// </summary>
        protected void IPSecurity_AuthorizeRequest(object sender, EventArgs e)
        {
            var app      = (HttpApplication)sender;
            var clientIP = Req.GetIP();
            var config   = WebIPSecurityConfigs.ConfigEntity;

            //app.Response.Write($"<!--{location.Area}|| {location.Province}|| {location.City}|| {location.Address}-->");

            // 循环所有跳转规则
            if (config.IPList.Select(ip => IpAdress.IsContains(clientIP, ip)).Any(result => config.IsBlacklistMode == result))
            {
                Jump(app.Context); return;
            }

            // 中文地址的方式
            if (config.AddressList.Count <= 0)
            {
                return;
            }
            var location = IpAdress.GetLocation(clientIP);

            if (config.IsBlacklistMode != config.AddressList.Any(o => location.Area.Contains(o) || location.Province.Contains(o) || location.City.Contains(o) || location.Address.Contains(o)))
            {
                return;
            }
            Jump(app.Context);
        }
        internal Response ConvertToIpApi(IpAdress ipAdress = null, Dictionary <string, JToken> geolocationData = null)
        {
            Response ipApi = null;

            if (ipAdress != null)
            {
                var     lonOb = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.lon)?.VALUE;
                decimal lon   = 0;
                decimal.TryParse(lonOb.ToString(), out lon);

                var     latOb = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.lat)?.VALUE;
                decimal lat   = 0;
                decimal.TryParse(lonOb.ToString(), out lat);

                ipApi = new Response()
                {
                    status      = ResponseEnum.TransacionSucces.ToString(),
                    country     = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.country)?.VALUE.ToString(),
                    countryCode = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.countryCode)?.VALUE.ToString(),
                    region      = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.region)?.VALUE.ToString(),
                    regionName  = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.regionName).VALUE.ToString(),
                    city        = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.city)?.VALUE.ToString(),
                    zip         = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.zip)?.VALUE.ToString(),
                    lat         = lat,
                    lon         = lon,
                    timezone    = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.timezone)?.VALUE.ToString(),
                    isp         = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.isp)?.VALUE.ToString(),
                    org         = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.org)?.VALUE.ToString(),
                    AS          = ipAdress.ipAdressData.FirstOrDefault(f => f.ID_DATA_TYPE == (int)DataTypeEnum.AS)?.VALUE.ToString()
                };
            }
            if (geolocationData != null && geolocationData["status"].ToString() != "fail")
            {
                var     lonOb = geolocationData.ContainsKey(DataTypeEnum.lon.ToString()) ? geolocationData[DataTypeEnum.lon.ToString()].ToString() : string.Empty;
                decimal lon   = 0;
                decimal.TryParse(lonOb, out lon);

                var     latOb = geolocationData.ContainsKey(DataTypeEnum.lat.ToString()) ? geolocationData[DataTypeEnum.lat.ToString()].ToString() : string.Empty;
                decimal lat   = 0;
                decimal.TryParse(latOb, out lat);

                ipApi = new Response()
                {
                    status      = ResponseEnum.TransacionSucces.ToString(),
                    country     = geolocationData.ContainsKey(DataTypeEnum.country.ToString()) ? geolocationData[DataTypeEnum.country.ToString()].ToString() : string.Empty,
                    countryCode = geolocationData.ContainsKey(DataTypeEnum.countryCode.ToString()) ? geolocationData[DataTypeEnum.countryCode.ToString()].ToString() : string.Empty,
                    region      = geolocationData.ContainsKey(DataTypeEnum.region.ToString()) ? geolocationData[DataTypeEnum.region.ToString()].ToString() : string.Empty,
                    regionName  = geolocationData.ContainsKey(DataTypeEnum.regionName.ToString()) ? geolocationData[DataTypeEnum.regionName.ToString()].ToString() : string.Empty,
                    city        = geolocationData.ContainsKey(DataTypeEnum.city.ToString()) ? geolocationData[DataTypeEnum.city.ToString()].ToString() : string.Empty,
                    zip         = geolocationData.ContainsKey(DataTypeEnum.zip.ToString()) ? geolocationData[DataTypeEnum.zip.ToString()].ToString() : string.Empty,
                    lat         = lat,
                    lon         = lon,
                    timezone    = geolocationData.ContainsKey(DataTypeEnum.timezone.ToString()) ? geolocationData[DataTypeEnum.timezone.ToString()].ToString() : string.Empty,
                    isp         = geolocationData.ContainsKey(DataTypeEnum.isp.ToString()) ? geolocationData[DataTypeEnum.isp.ToString()].ToString() : string.Empty,
                    org         = geolocationData.ContainsKey(DataTypeEnum.org.ToString()) ? geolocationData[DataTypeEnum.org.ToString()].ToString() : string.Empty,
                    AS          = geolocationData.ContainsKey(DataTypeEnum.AS.ToString()) ? geolocationData[DataTypeEnum.AS.ToString()].ToString() : string.Empty,
                };
            }
            return(ipApi);
        }
Exemple #3
0
        public override string ToString()
        {
            string name = "Unknown/Generic PI";

            switch (BoardType)
            {
            case RaspberryPiBoards.Model_2:
                name = "Raspberry Pi 2";
                break;

            case RaspberryPiBoards.Model_A:
                name = "Raspberry Pi, Model A";
                break;

            case RaspberryPiBoards.Model_B:
                name = "Raspberry Pi, Model B";
                break;

            case RaspberryPiBoards.Model_APlus:
                name = "Raspberry Pi, Model A+";
                break;

            case RaspberryPiBoards.Model_BPlus:
                name = "Raspberry Pi, Model B+";
                break;

            case RaspberryPiBoards.Bannana:
                name = "Bannana Pi, original";
                break;
            }

            string ip = (IpAdress != null) ? IpAdress.ToString() : "(N/A)";

            return(string.Format("{0} @ {1}", name, ip));
        }
        /// <summary>
        /// Methode die in einem eigenen Thread läuft
        /// Wartet auf Anfrage aus dem Netzwerk
        /// Sendet bei erfolgreicher Anfrage die IPAdresse in das Netzwerk
        /// </summary>
        private void WaitForClientRequest_UDP()
        {
            const String seperator = "-------------------------------------------------------------------------";

            try
            {
                while (!CloseApplication)
                {
                    UdpClient = new UdpClient();
                    Byte[] myBuffer = new Byte[4096];

                    IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 1336);
                    UdpClient.Client.Bind(remoteEndPoint);
                    ServerVM.WriteToLog($"UdpClient wurde geöffnet: Port: {1336}");
                    Console.WriteLine(DateTime.Now + " >>>>>>>>>>> " + "Waiting for BroadcastMessages..." + "<<<<<<<<<<");
                    ServerVM.WriteToLog(" >>>>>>>>>>> " + "Waiting for BroadcastMessages..." + "<<<<<<<<<<");
                    myBuffer = UdpClient.Receive(ref remoteEndPoint);
                    Console.WriteLine(Environment.NewLine + seperator);
                    Console.WriteLine(DateTime.Now + " Eine Anfrage kam von: " + remoteEndPoint);
                    ServerVM.WriteToLog(" Eine Anfrage kam von: " + remoteEndPoint);

                    ASCIIEncoding encoder        = new ASCIIEncoding();
                    String        messageFromUdp = encoder.GetString(myBuffer);

                    messageFromUdp.Replace("\0", "");
                    messageFromUdp.Trim();

                    Console.WriteLine(DateTime.Now + " Empfanges Schlüsselwort: " + messageFromUdp.Trim() + " von: " + IpAdress.ToString());
                    ServerVM.WriteToLog(" Empfanges Schlüsselwort: " + messageFromUdp.Trim() + " von: " + IpAdress.ToString());
                    Byte[] bufferToClient = new Byte[0];
                    if (messageFromUdp.Contains("<Server>")) //Server-Anfrage
                    {
                        Thread.Sleep(1000);
                        bufferToClient = encoder.GetBytes(IpAdress.ToString());
                        UdpClient.Send(bufferToClient, bufferToClient.Length, remoteEndPoint);
                        Console.WriteLine(DateTime.Now + " Gesendeter Broadcast: "
                                          + "\""
                                          + IpAdress.ToString()
                                          + "\" "
                                          + "an: "
                                          + IpAdress.ToString());
                        ServerVM.WriteToLog(" Gesendeter Broadcast: " + "\"" + IpAdress.ToString() + "\" " + "an: " + IpAdress.ToString());
                    }
                    else
                    {
                        Console.WriteLine(seperator);
                        Console.WriteLine(DateTime.Now + "Anfrage war ungültig");
                    }
                    Console.WriteLine(seperator + Environment.NewLine);
                    messageFromUdp = String.Empty;
                    UdpClient.Close();
                    ServerVM.WriteToLog("UdpClient wurde geschlossen");
                }
            }
            catch (Exception ex)
            {
                //Hier ging etwas schief :/
            }
        }
        internal Response GetIpData(string ip)
        {
            Response response = null;

            using (SqlConnection connection = new SqlConnection(GetConnectionString()))
            {
                connection.Open();
                SqlCommand commandIP = new SqlCommand("SELECT*FROM[AssignmentDB].[dbo].[IP_ADRESSES] WHERE [IP_ADRESS] = @IP_ADRESS", connection);
                commandIP.Parameters.AddWithValue("@IP_ADRESS", ip);
                SqlDataReader reader = commandIP.ExecuteReader();

                IpAdress ipAdress = null;
                while (reader.Read())
                {
                    ipAdress = new IpAdress()
                    {
                        ID_IP_ADRESS = reader.GetInt32(0),
                        IP_ADRESS    = reader.GetString(1)
                    };
                }
                reader.Close();
                if (ipAdress != null)
                {
                    ipAdress.ipAdressData = new List <IpAdressData>();
                    SqlCommand commandIpData = new SqlCommand("SELECT*FROM[AssignmentDB].[dbo].[IP_ADRESSES_DATA] WHERE [ID_IP_ADRESS] = @ID_IP_ADRESS", connection);
                    commandIpData.Parameters.AddWithValue("@ID_IP_ADRESS", ipAdress.ID_IP_ADRESS);
                    reader = commandIpData.ExecuteReader();
                    while (reader.Read())
                    {
                        IpAdressData ipAdressData = new IpAdressData()
                        {
                            ID_IP_ADRESSES_DATA = reader.GetInt32(0),
                            ID_IP_ADRESS        = ipAdress.ID_IP_ADRESS,
                            ID_DATA_TYPE        = reader.GetInt64(2),
                            VALUE     = reader.GetSqlValue(3),
                            DATA_TYPE = GetDataType(reader.GetInt64(2))
                        };
                        ipAdress.ipAdressData.Add(ipAdressData);
                    }
                }
                response = ConvertToIpApi(ipAdress);
                connection.Close();
            }

            return(response);
        }
Exemple #6
0
        public void Init()
        {
            _sampleInputs = new[]
            {
                "abba[mnop]qrst",
                "abcd[bddb]xyyx",
                "aaaa[qwer]tyui",
                "ioxxoj[asdfgh]zxcvbn",
            };
            _sampleSslInputs = new[]
            {
                "aba[bab]xyz",
                "xyx[xyx]xyx",
                "aaa[kek]eke",
                "zazbz[bzb]cdb",
            };

            _adress = new IpAdress("");
        }
Exemple #7
0
        //Infinite listening loop
        void ListenConnections()
        {
            if (IpAdress.Equals("localhost"))
            {
                listener = new TcpListener(IPAddress.Any, PortNumber);
            }
            else
            {
                IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress   ipAddress  = null;
                foreach (IPAddress addr in ipHostInfo.AddressList)
                {
                    if (addr.ToString().Equals(IpAdress))
                    {
                        ipAddress = addr;
                    }
                }
                if (ipAddress == null)
                {
                    ChatApp.LogMessage("Unable to listen in the specified address");
                    return;
                }
                else
                {
                    listener = new TcpListener(ipAddress, PortNumber);
                }
            }

            listener.Start();
            ChatApp.LogMessage("Listening to connections...");

            try
            {
                TcpClient client = listener.AcceptTcpClient();
                ChatApp.LogMessage("Client received");
                StartProtocol(client);
            }
            catch (Exception)
            {
                return;
            }
        }
 public override int GetHashCode()
 {
     return(ControllerName.GetHashCode() ^
            ActionName.GetHashCode() ^
            IpAdress.GetHashCode());
 }
Exemple #9
0
 bool CanChangeChild()
 {
     return(IpAdress.Trim().Length != 0);
 }