Ejemplo n.º 1
0
        public void WritePackets(List <Packet> packets)
        {
            SQLiteCommand insertPacket = new SQLiteCommand();

            sqliteConnection.Open();
            insertPacket.Connection = sqliteConnection;
            foreach (Packet packet in packets)
            {
                insertPacket.CommandText = "INSERT INTO Packet (Protocol, Length, Time, Source_MAC, Source_IP, Source_Port, Dest_MAC, Dest_IP, Dest_Port) VALUES ("
                                           + '\'' + packet.Protocol + '\'' + ","
                                           + '\'' + packet.Length + '\'' + ","
                                           + '\'' + packet.Time + '\'' + ","
                                           + '\'' + EncryptionHandler.Encrypt(packet.Source_MAC) + '\'' + ","
                                           + '\'' + EncryptionHandler.Encrypt(packet.Source_IP) + '\'' + ","
                                           + '\'' + packet.Source_Port + '\'' + ","
                                           + '\'' + EncryptionHandler.Encrypt(packet.Dest_MAC) + '\'' + ","
                                           + '\'' + EncryptionHandler.Encrypt(packet.Dest_IP) + '\'' + ","
                                           + '\'' + packet.Dest_Port + '\'' + ");";
                insertPacket.ExecuteNonQuery();
            }
            sqliteConnection.Close();
        }
Ejemplo n.º 2
0
        private void UpdateRemoteDevices(Dictionary <string, Device> remoteDevicesToUpdate)
        {
            SQLiteCommand updateRemoteDevices = new SQLiteCommand(sqliteConnection);

            sqliteConnection.Open();
            foreach (KeyValuePair <string, Device> kvp in remoteDevicesToUpdate)
            {
                if (remoteDevices.ContainsKey(kvp.Key))
                {
                    updateRemoteDevices.CommandText = "UPDATE Remote_Device SET Packets = " + (kvp.Value.Packets + remoteDevices[kvp.Key].Packets) + ", Total_Data = " + (kvp.Value.TotalData + remoteDevices[kvp.Key].TotalData) + " WHERE MAC_Address = " + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) b + '\'' + ";";
                }
                else
                {
                    updateRemoteDevices.CommandText = "INSERT INTO Remote_Device (MAC_Address, IP_Address, Packets, Total_Data) VALUES (" + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) + '\'' + "," + '\'' + EncryptionHandler.Encrypt(kvp.Value.IP_Address) + '\'' + "," + kvp.Value.Packets + "," + kvp.Value.TotalData + ");";
                }
                updateRemoteDevices.ExecuteNonQuery();
            }
            sqliteConnection.Close();
        }
Ejemplo n.º 3
0
        private void UpdateLocalDevices(Dictionary <string, Device> localDevicesToUpdate)
        {
            SQLiteCommand updateLocalDevices = new SQLiteCommand(sqliteConnection);

            sqliteConnection.Open();
            foreach (KeyValuePair <string, Device> kvp in localDevicesToUpdate)
            {
                if (localDevices.ContainsKey(kvp.Key))
                {
                    updateLocalDevices.CommandText = "UPDATE Local_Device SET Packets = " + (kvp.Value.Packets + localDevices[kvp.Key].Packets) + ", Total_Data = " + (kvp.Value.TotalData + localDevices[kvp.Key].TotalData) + " WHERE MAC_Address = " + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) + '\'' + ";";
                }
                else
                {
                    updateLocalDevices.CommandText = "INSERT INTO Local_Device (MAC_Address, IP_Address, Packets, Total_Data) VALUES (" + '\'' + EncryptionHandler.Encrypt(kvp.Value.MAC_Address) + '\'' + "," + '\'' + EncryptionHandler.Encrypt(kvp.Value.IP_Address) + '\'' + "," + kvp.Value.Packets + "," + kvp.Value.TotalData + ");";

                    /*
                     * PushbulletClient client = new PushbulletClient("DA API KEY");
                     * var currentUserInformation = client.CurrentUsersInformation();
                     *
                     * if (currentUserInformation != null)
                     * {
                     *  PushNoteRequest reqeust = new PushNoteRequest()
                     *  {
                     *      Email = currentUserInformation.Email,
                     *      Title = "New Device on network",
                     *      Body = "Device Mac: " + kvp.Value.MAC_Address + "\nDevice IP: " + kvp.Value.IP_Address
                     *  };
                     *
                     *  PushResponse response = client.PushNote(reqeust);
                     * }
                     */
                }
                updateLocalDevices.ExecuteNonQuery();
            }
            sqliteConnection.Close();
        }