Last active
August 29, 2015 14:01
-
-
Save sstelfox/bf8f2a6bf3231487670e to your computer and use it in GitHub Desktop.
Sample using native ruby to only update information about hosts that were within the scope of the scan.
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 | |
| require 'ipaddr' | |
| # Hosts that we're already aware of by IP | |
| known_hosts = %w{ 127.0.0.1 192.168.122.5 192.168.122.20 192.168.122.48 | |
| 192.168.122.134 192.168.122.200 192.168.122.210 192.168.122.230 } | |
| # A new task has completed with the following target (only covers | |
| # 192.168.122.0-192.168.122.127) | |
| scan_target = '192.168.122.0/25' | |
| new_host_list = %w{ 192.168.122.5 192.168.122.20 } | |
| # This will hold the updated list of known hosts after processing | |
| post_scan_result = [] | |
| # This could probably be a bit more efficient but it works as a proof of | |
| # concept. | |
| range = IPAddr.new(scan_target) | |
| known_hosts.each do |host| | |
| if range.include?(host) | |
| post_scan_result << host if new_host_list.include?(host) | |
| next | |
| end | |
| # This host is outside of the scope of our scan | |
| post_scan_result << host | |
| end | |
| # This will only be missing 192.168.122.48 | |
| puts post_scan_result.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment