CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/opt_address.rb
Views: 11780
1
# -*- coding: binary -*-
2
3
module Msf
4
5
###
6
#
7
# Network address option.
8
#
9
###
10
class OptAddress < OptBase
11
def type
12
return 'address'
13
end
14
15
def valid?(value, check_empty: true)
16
return false if check_empty && empty_required_value?(value)
17
return false unless value.kind_of?(String) or value.kind_of?(NilClass)
18
19
if (value != nil and value.empty? == false)
20
begin
21
getaddr_result = ::Rex::Socket.getaddress(value, true)
22
# Covers a wierdcase where an incomplete ipv4 address will have it's
23
# missing octets filled in with 0's. (e.g 192.168 become 192.0.0.168)
24
# which does not feel like a legit behaviour
25
if value =~ /^\d{1,3}(\.\d{1,3}){1,3}$/
26
return false unless value =~ Rex::Socket::MATCH_IPV4
27
end
28
rescue
29
return false
30
end
31
end
32
33
return super
34
end
35
end
36
37
end
38
39