Script tweaks - added start of stack overflow script

This commit is contained in:
Jonathan Hodgson 2019-10-23 20:32:18 +01:00
parent 50c38d4349
commit 1a0c852712
5 changed files with 707 additions and 0 deletions

52
bin/.bin/nmap/nmap-get-json Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env bash
file="$1"
# Shift the attributes so we can ignore the filename easily
shift
if [ ! -n "$file" ]; then
echo "You must provide an xml file"
exit 1
fi
json=$(php -r "echo json_encode(simplexml_load_file('$file'));" 2> /dev/null)
if [[ "$json" == "false" ]]; then
echo "Please provide a valid xml file"
exit 1
fi
function print_basic_info(){
echo $json | # Echo the full json file
jq ' if ( .host | type ) == "object" then [ .host ] else .host end ' | # Get the hosts as an array (even if there is only one
#jq '.[0]'
jq '[ .[] | {
address: .address."@attributes".addr,
port: {
tcp : (try ( [ .ports.port[] | select( ."@attributes".protocol == "tcp" ) | {
port: ."@attributes".portid,
service: .service."@attributes",
} ] ) catch null ),
udp : (try ( [ .ports.port[] | select( ."@attributes".protocol == "udp" ) | {
port: ."@attributes".portid,
service: .service."@attributes",
} ] ) catch null )
}
} ]'
#.ports.port[] | [ . ]
#| [select(."@attributes".protocol)]
}
if [ -n "$1" ] ; then
case "$1" in
-h|--help)
#print_help
exit 0
;;
basic)
print_basic_info
exit 0
;;
esac
fi