Skip to content

Instantly share code, notes, and snippets.

@pcarrier
Last active January 4, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcarrier/8663328 to your computer and use it in GitHub Desktop.
Save pcarrier/8663328 to your computer and use it in GitHub Desktop.
Nasty scripts to extract initial window sizes from nmap-os-db. Results on http://gcarrier.fr/windowsizes.html
#!/usr/bin/env ruby
require 'json'
text = STDIN.read
data = {}
extract = text.split("\n\n").collect do |block|
lines = block.split("\n")
no_comment = lines.reject do |l|
l[0] == '#'
end
next if no_comment.empty?
# Skip the first record
next if no_comment.first.start_with? 'MatchPoints'
kv = no_comment.collect do |l|
l.split(/[ \(]/, 2)
end
name = kv.find { |k, v| k == 'Fingerprint' }[1]
winline = kv.find { |k, v| k == 'WIN' }[1]
next if winline == 'R=N)'
res = winline[0..-2].split('%').collect { |s|
_, v = s.split('=',2)
v.split('|').collect{|s|s.to_i(16)}
}
[name] + res
end.compact
puts JSON.dump extract
#!/usr/bin/env ruby
require 'json'
require 'cgi'
print '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Initial window sizes</title><body><table>
<tr><th>Name</th><th>W1</th><th>W2</th><th>W3</th><th>W4</th><th>W5</th><th>W6</th></tr>'
JSON::parse(STDIN.read).each do |cols|
name = cols.shift
print "<tr><td>#{CGI.escapeHTML name}</td>"
cols.each do |col|
print "<td>#{col.join ', '}</td>"
end
puts '</tr>'
end
print '</table></body></html>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment