Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
acknowledged_scanners
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Degen, Bernhard (UT-EEMCS)
acknowledged_scanners
Commits
c45cba66
Commit
c45cba66
authored
2 years ago
by
Degen, Bernhard (UT-EEMCS)
Browse files
Options
Downloads
Patches
Plain Diff
Implement csv output with option to unroll subnets
parent
5a885dc5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/asutil.py
+23
-3
23 additions, 3 deletions
bin/asutil.py
with
23 additions
and
3 deletions
bin/asutil.py
+
23
−
3
View file @
c45cba66
...
...
@@ -12,6 +12,7 @@ import distutils.spawn
import
os
import
sys
import
time
from
ipaddress
import
IPv4Network
#
#
...
...
@@ -26,6 +27,8 @@ else:
dr_default
=
os
.
path
.
join
(
os
.
getcwd
(),
'
data
'
)
act_choices
=
[
'
list
'
,
'
text
'
,
'
pmap
'
,
'
csv
'
,
'
none
'
]
parser
=
argparse
.
ArgumentParser
(
description
=
'
Process acknowledged scanner data
'
)
parser
.
add_argument
(
'
-u
'
,
'
--unroll
'
,
default
=
False
,
action
=
'
store_true
'
,
help
=
'
Adds all IP addresses in a subnet as separate entries
'
)
parser
.
add_argument
(
'
-d
'
,
'
--dataroot
'
,
default
=
dr_default
,
help
=
'
Specifies the data directory; defaults to %s
'
%
(
dr_default
))
parser
.
add_argument
(
'
-f
'
,
'
--filter
'
,
action
=
'
append
'
,
...
...
@@ -178,14 +181,27 @@ def act_output_pmap_text(tags, metadata, dataroot):
result
.
append
(
"
%-20s %s
"
%
(
j
,
i
))
return
result
def
act_output_csv
():
def
act_output_csv
(
tags
,
dataroot
,
unroll
):
"""
act_output_csv(tags, metadata) -> string
outputs the contents of the tagged directories as a csv file with the
organization and the ip.
"""
return
result
=
[
"
ip,org
"
]
for
i
in
tags
:
fn
=
os
.
path
.
join
(
dataroot
,
i
,
'
ips.txt
'
)
ip_filedata
=
load_ip_file
(
fn
)
if
ip_filedata
is
not
None
:
for
j
in
ip_filedata
:
# Check to see if the line specifies a subnet (has a '/').
# If not, add all addresses within the subnet
if
unroll
and
j
.
find
(
'
/
'
)
!=
-
1
:
for
ip
in
IPv4Network
(
j
):
result
.
append
(
"
%s,%s
"
%
(
ip
,
i
))
else
:
result
.
append
(
"
%s,%s
"
%
(
j
,
i
))
return
result
if
__name__
==
'
__main__
'
:
startup
(
args
)
...
...
@@ -207,5 +223,9 @@ if __name__ == '__main__':
results
=
act_output_pmap_text
(
targets
,
org_data
,
args
.
dataroot
)
for
i
in
results
:
print
(
i
)
elif
args
.
action
==
'
csv
'
:
results
=
act_output_csv
(
targets
,
args
.
dataroot
,
args
.
unroll
)
for
i
in
results
:
print
(
i
)
sys
.
exit
(
1
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment