#!/usr/bin/env ruby

unless STDIN.tty?  # we are in a pipeline
	last_ip = nil
	linux_file=File.new("linux.txt","w")
	windows_file=File.new("windows.txt","w")

	while((line = STDIN.gets))
		if /Interesting.*\(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\)/.match(line)
			last_ip=$1
		end
		if /OS details:(.*)/.match(line)
			unless last_ip==nil
				case $1
				when /linux/i
					puts "Linux on "+last_ip
					linux_file.puts(last_ip)
				when /windows/i
					puts "Wndows on "+last_ip
					windows_file.puts(last_ip)
				end
			end
		end
	end

	linux_file.close
	windows_file.close
else
	puts "This script expects you to pipe the output from nmap -O into it"
end
