Last active
April 27, 2018 07:46
-
-
Save decal/bd55981facc9280b325cbb80895d4120 to your computer and use it in GitHub Desktop.
🌏 Rewrite "greppable" output generated by the `nmap` argument `-oG`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
# | |
# Parse nmap grepable output and display host IP address with open port numbers on each line | |
# | |
# Written By: Derek Callaway [derek.callaway (AT) ioactive {D0T} com] | |
# ProductName: Mac OS X 10.13.2 17C88 | |
# Last Updated: Sat Dec 23 15:49:49 PST 2017 | |
# | |
if ARGV.size < 1 | |
STDERR.puts("usage: #{$0} FILE") | |
STDERR.puts | |
STDERR.puts(' FILE path to file containing NMap grepable output created by nmap(1) -oG') | |
STDERR.puts | |
end | |
lines = File.readlines(ARGV.first) | |
lines.each do |l| | |
next if !l.include?('/open') | |
a = l.split | |
h = a[1] | |
f = true | |
a.each do |b| | |
c = b.split(',') | |
c.each do |d| | |
if d =~ %r{^[0-9]} and d.include?('/') | |
e = d.split('/') | |
if e[1].eql?('open') | |
if f | |
print h | |
print ' ' | |
f = false | |
end | |
print e.first | |
print ' ' | |
end | |
end | |
end | |
end | |
puts if !f | |
end | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment