Module: Msf::DBManager::IPAddress
- Included in:
- Msf::DBManager
- Defined in:
- lib/msf/core/db_manager/ip_address.rb
Instance Method Summary collapse
- #ipv46_validator(addr) ⇒ Object
- #ipv4_validator(addr) ⇒ Object
- #ipv6_validator(addr) ⇒ Object
- #rfc3330_reserved(ip) ⇒ Object
-
#validate_ips(ips) ⇒ Object
Takes a space-delimited set of ips and ranges, and subjects them to RangeWalker for validation.
Instance Method Details
#ipv46_validator(addr) ⇒ Object
2 3 4 |
# File 'lib/msf/core/db_manager/ip_address.rb', line 2 def ipv46_validator(addr) ipv4_validator(addr) or ipv6_validator(addr) end |
#ipv4_validator(addr) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/msf/core/db_manager/ip_address.rb', line 6 def ipv4_validator(addr) if addr.try(:ipv4?) true elsif addr.kind_of? String Rex::Socket.is_ipv4?(addr) else false end end |
#ipv6_validator(addr) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/msf/core/db_manager/ip_address.rb', line 16 def ipv6_validator(addr) if addr.try(:ipv6?) true elsif addr.kind_of? String Rex::Socket.is_ipv6?(addr) else false end end |
#rfc3330_reserved(ip) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/msf/core/db_manager/ip_address.rb', line 26 def rfc3330_reserved(ip) case ip when PacketFu::Octets ip_x = ip.to_x ip_i = ip.to_i when String if ipv46_validator(ip) ip_x = ip ip_i = Rex::Socket.addr_atoi(ip) else raise ArgumentError, "Invalid IP address: #{ip.inspect}" end when Integer if (0..2**32-1).include? ip ip_x = Rex::Socket.addr_itoa(ip) ip_i = ip else raise ArgumentError, "Invalid IP address: #{ip.inspect}" end else raise ArgumentError, "Invalid IP address: #{ip.inspect}" end return true if Rex::Socket::RangeWalker.new("0.0.0.0-0.255.255.255").include? ip_x return true if Rex::Socket::RangeWalker.new("127.0.0.0-127.255.255.255").include? ip_x return true if Rex::Socket::RangeWalker.new("169.254.0.0-169.254.255.255").include? ip_x return true if Rex::Socket::RangeWalker.new("224.0.0.0-239.255.255.255").include? ip_x return true if Rex::Socket::RangeWalker.new("255.255.255.255-255.255.255.255").include? ip_x return false end |
#validate_ips(ips) ⇒ Object
Takes a space-delimited set of ips and ranges, and subjects them to RangeWalker for validation. Returns true or false.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/msf/core/db_manager/ip_address.rb', line 58 def validate_ips(ips) ret = true begin ips.split(/\s+/).each {|ip| unless Rex::Socket::RangeWalker.new(ip).ranges ret = false break end } rescue ret = false end return ret end |