Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
url-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
url-checker
Commits
04a267cf
Commit
04a267cf
authored
Dec 05, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Report dns query status
parent
c702d4fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
10 deletions
+63
-10
urlchecker_dns.py
urlchecker_dns.py
+63
-10
No files found.
urlchecker_dns.py
View file @
04a267cf
import
dns
from
urlchecker_network
import
logNetwork
from
peewee
import
fn
URL_TO_CHECK
=
"example.org"
TIMEOUT
=
2
def
reportDnsQuery
(
db
,
resolver_ip
=
None
,
domain
=
None
,
rdtype
=
None
):
# http://charlesleifer.com/blog/techniques-for-querying-lists-of-objects-and-determining-the-top-related-item/
DnsChangeAlias
=
db
.
DnsChange
.
alias
()
subquery
=
(
DnsChangeAlias
.
select
(
DnsChangeAlias
.
resolver_ip
,
DnsChangeAlias
.
domain
,
DnsChangeAlias
.
rdtype
,
fn
.
MAX
(
DnsChangeAlias
.
status_id
).
alias
(
"max_status_id"
),
)
.
group_by
(
DnsChangeAlias
.
resolver_ip
,
DnsChangeAlias
.
domain
,
DnsChangeAlias
.
rdtype
,
)
.
alias
(
"dns_change_max_subquery"
)
)
StatusAlias
=
db
.
Status
.
alias
()
query
=
(
db
.
DnsChange
.
select
(
db
.
DnsChange
,
StatusAlias
)
.
join
(
StatusAlias
)
.
switch
(
db
.
DnsChange
)
.
join
(
subquery
,
on
=
(
(
db
.
DnsChange
.
status_id
==
subquery
.
c
.
max_status_id
)
&
(
db
.
DnsChange
.
resolver_ip
==
subquery
.
c
.
resolver_ip
)
&
(
db
.
DnsChange
.
domain
==
subquery
.
c
.
domain
)
&
(
db
.
DnsChange
.
rdtype
==
subquery
.
c
.
rdtype
)
),
)
.
order_by
(
db
.
DnsChange
.
domain
.
asc
(),
db
.
DnsChange
.
rdtype
.
asc
(),
db
.
DnsChange
.
resolver_ip
.
asc
(),
)
)
if
resolver_ip
is
not
None
:
if
type
(
resolver_ip
)
==
list
:
query
=
query
.
where
(
db
.
DnsChange
.
resolver_ip
<<
resolver_ip
)
else
:
query
=
query
.
where
(
db
.
DnsChange
.
resolver_ip
==
resolver_ip
)
if
domain
is
not
None
:
if
type
(
domain
)
==
list
:
query
=
query
.
where
(
db
.
DnsChange
.
domain
<<
domain
)
else
:
query
=
query
.
where
(
db
.
DnsChange
.
domain
==
domain
)
if
rdtype
is
not
None
:
if
type
(
rdtype
)
==
list
:
query
=
query
.
where
(
db
.
DnsChange
.
rdtype
<<
rdtype
)
else
:
query
=
query
.
where
(
db
.
DnsChange
.
rdtype
==
rdtype
)
return
query
def
logDnsQuery
(
db
,
status_id
,
resolver_ip
,
domain_text
,
rdtype
,
answer_list
):
answer_list
.
sort
()
response
=
", "
.
join
(
answer_list
)
...
...
@@ -12,16 +72,9 @@ def logDnsQuery(db, status_id, resolver_ip, domain_text, rdtype, answer_list):
with
db
.
_db
.
atomic
():
try
:
# Check previous parameter value
previous_entry
=
(
db
.
DnsChange
.
select
()
.
where
(
db
.
DnsChange
.
resolver_ip
==
resolver_ip
,
db
.
DnsChange
.
domain
==
domain_text
,
db
.
DnsChange
.
rdtype
==
rdtype
,
)
.
order_by
(
db
.
DnsChange
.
status
.
desc
())
.
get
()
)
previous_entry
=
reportDnsQuery
(
db
,
resolver_ip
=
resolver_ip
,
domain
=
domain_text
,
rdtype
=
rdtype
).
get
()
except
db
.
DnsChange
.
DoesNotExist
:
previous_entry
=
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment