-
Notifications
You must be signed in to change notification settings - Fork 8
/
results.py
executable file
·63 lines (52 loc) · 1.53 KB
/
results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
from fire.core import Fire
from pony.orm import db_session
from lib.models import Host, Port, sql_debug
@db_session
def main(query='', port='', tag='', sdt=False, sp=True, sc=True, sb=False, sd=False, st=False, d=False, limit=None):
"""Display stats or search in db"""
from pony.orm.core import select
if d:
sql_debug(True)
if not any((query, port, tag)):
from pony.utils.utils import count
print('Stats by port')
select((p.num, p.tags, count(p)) for p in Port).show()
print('Stats for rtsp')
select((p.paths.cred.user, p.paths.cred.password, count()) for p in Port if p.num == 554).show()
return
res = select(
(p.created_at, t.ip, p.num, p.comment, p.banner, p.data, p.tags)
for t in Host for p in t.ports
if (
query in p.comment
or
query in p.banner
or
query in p.tags
or
query in str(p.num)
or
query in t.ip
)
and
(tag in p.tags)
).limit(limit)
for d, ip, p, c, b, data, t in res:
parts = []
if sdt:
parts.append(d.strftime('%m-%d %H:%M'))
parts.append(ip)
if sp:
parts.append(p)
if sc:
parts.append(c)
if sb:
parts.append(b)
if sd:
parts.append(data)
if st:
parts.append(','.join(t))
print(*parts)
if __name__ == "__main__":
Fire(main)