Filter packets by ttl Scapy? - scapy

I need to have Scapy filter by ttl (e.g.: sniff(iface = 'eth0', filter = 'ttl 128') ) but can't seem to find the right syntax for the command to work. Is this possible?

I am not aware of a ttl keyword for BPF filters, you can do it like that though:
sniff(iface = 'eth0', filter = 'ip[8] == 128')

Related

How Can I Sort These Many To Many Values Without a Through Table?

I am trying to compare the values in two manytomany fields...this almost works...
author_confirm = Author.objects.filter(id=self.object.update_reader_id).values_list('author_confirm').order_by('pk')
author = Author.objects.filter(id=self.object.update_reader_id).values_list('author').order_by('pk')
authors_are_equal = list(author) == list(author_confirm)
authors_are_not_equal = list(author) != list(author_confirm)
This works in that it gets me the values...but doesn't seem to be cooperating with the order_by...I currently have both fields with identical values...but their PKs are transposed so it tells me these fields are not identical...which is technically correct...but I see the problem is that the PKs are not listed in order...Is there a way to do this without a Through Table?
I am using UUIDs as the primary key....I'm not sure if this is relevant or not...but nonetheless I can't seem to get the values in an ordered way.
Thanks in advance for any ideas.
You should order by the author__pk and author_confirmed__pk, otherwise you are only ordering by the author object itself, which we lready know: that is the self.object.update_reader_id, hence the problem:
author_confirm = (
Author.objects.filter(id=self.object.update_reader_id)
.values_list('author_confirm')
.order_by('author_confirm__pk')
)
author = (
Author.objects.filter(id=self.object.update_reader_id)
.values_list('author')
.order_by('author__pk')
)

Setting TTL/Record Expiry in hazelcast for individual entries without a put

Is it possible to set ttl/record-expiry on an individual key without doing a put i.e, without changing the value of key. Something similar to EXPIRE in redis?
I can do a "get" followed by "put" and set the ttl but that would be in-efficient with large values.
hz = hazelcast.HazelcastClient()
test_map = hz.get_map('test_map')
val = test_map.get(key)
test_map.put(key, val, ttl)
Note - I am using hazelcast-python-client
You can adjust TTL with changing anything else with the map.setTtl() method:
IMap map = hz.getMap("testMap"); // get the map
map.setTtl("keyToModify", 1, TimeUnit.HOURS);

How to check if ArangoDB query is not empty?

I would like to make an exists PostgreSQL query.
Let's say I have a Q ArangoDB query (AQL). How can I check if Q returns any result?
Example:
Q = "For u in users FILTER 'x#example.com' = u.email"
What is the best way to do it (most performant)?
I have ideas, but couldn't find an easy way to measure the performance:
Idea 1: using Length:
RETURN LENGTH(%Q RETURN 1) > 0
Idea 2: using Frist:
RETURN First(%Q RETURN 1) != null
Above, %Q is a substitution for the query defined at the beginning.
I think the best way to achieve this for a generic selection query with a structure like
Q = "For u in users FILTER 'x#example.com' = u.email"
is to first add a LIMIT clause to the query, and only make it return a constant value (in contrast to the full document).
For example, the following query returns a single match if there is such document or an empty array if there is no match:
FOR u IN users FILTER 'x#example.com' == u.email LIMIT 1 RETURN 1
(please note that I also changed the operator from = to == because otherwise the query won't parse).
Please note that this query may benefit a lot from creating an index on the search attribute, i.e. email. Without the index the query will do a full collection scan and stop at the first match, whereas with the index it will just read at most a single index entry.
Finally, to answer your question, the template for the EXISTS-like query will then become
LENGTH(%Q LIMIT 1 RETURN 1)
or fleshed out via the example query:
LENGTH(FOR u IN users FILTER 'x#example.com' == u.email LIMIT 1 RETURN 1)
LENGTH(...) will return the number of matches, which in this case will either be 0 or 1. And it can also be used in filter conditions like as follows
FOR ....
FILTER LENGTH(...)
RETURN ...
because LENGTH(...) will be either 0 or 1, which in context of a FILTER condition will evaluate to either false or true.
Do you need and AQL solution?
Only the count:
var q = "For u in users FILTER 'x#example.com' = u.email";
var res = db._createStatement({query: q, count: true}).execute();
var ct = res.count();
Is the fastest I can think of.

How do you add elements to a set with DataStax QueryBuilder?

I have a table whose column types are
text, bigint, set<text>
I'm trying to update a single row and add an element to the set using QueryBuilder.
The code that overwrites the existing set looks like this (note this is scala):
val query = QueryBuilder.update("twitter", "tweets")
.`with`(QueryBuilder.set("sinceid", update.sinceID))
.and(QueryBuilder.set("tweets", setAsJavaSet(update.tweets)))
.where(QueryBuilder.eq("handle", update.handle))
I was able to find the actual CQL for adding an element to a set which is:
UPDATE users
SET emails = emails + {'fb#friendsofmordor.org'} WHERE user_id = 'frodo';
But could not find an example using QueryBuilder.
Based off of the CQL I also tried:
.and(QueryBuilder.set("tweets", "tweets"+{setAsJavaSet(update.tweets)}))
But it did not work. Thanks in advance
Use add (add one element at a time) or addAll (more than one any number of element at a time) method to add to a set.
To extend Ananth's answer:
QueryBuilder.add does not support BindMarker. To use BindMarker while adding in set, it is required to use QueryBuilder.addAll only.*
*Just a note, Collections.singleton may come in handy in this regard.
Using #Ananth and #sazzad answers, the code below works:
Session cassandraSession;
UUID uuid;
Long value;
Statement queryAddToSet = QueryBuilder
.update("tableName")
.with(QueryBuilder.addAll("setFieldName", QueryBuilder.bindMarker()))
.where(QueryBuilder.eq("whereFieldName", QueryBuilder.bindMarker()));
PreparedStatement preparedQuery = cassandraSession.prepare(queryAddToSet);
BoundStatement boundQuery = preparedQuery.bind();
boundQuery
.setUUID("whereFieldName", uuid)
.setSet("setFieldName", Collections.singleton(value));
session.execute(boundQuery);

How do I configure the sort order of results returned by DBSet local?

I want to be able to configure the sort order of a binding source based on DBSet<> local
By passing the number of a field in the resultant query.
i.e order by the nth field in the query.
I am guessing I would be needing to use the .OrderBy() method, but dont know what to pass into it.
I know that I need
Here is the code that sets up the binding source.
var dset = base.Context.Organisations;
if (QuickSearch == null) QuickSearch = "";
var qry = dset.Where(p => p.Name.Contains(QuickSearch));
qry.Load();
bindingSource.DataSource = dset.Local.ToBindingList();
The following code may help-
_bindingSource.Sort = "ColumnName ASC";
OR
_bindingSource.Sort = "ColumnName DESC";
OR
_bindingSource.Sort = "ColumnName1 ASC, ColumnName2 DESC";
and so on......

Resources