Skip to content

Commit

Permalink
Upstream socket.rb matchers
Browse files Browse the repository at this point in the history
Add regex for matching MAC addresses, as well as convenience
methods for checking if a string matches the regex, as well as a
generic :is_ip? method to verify if something is either IPv4 or v6.
  • Loading branch information
RageLtMan committed Jun 25, 2017
1 parent 4ebdb86 commit bdbdd27
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/rex/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def self.create_ip(opts = {})

MATCH_IPV4_PRIVATE = /^\s*(?:10\.|192\.168|172.(?:1[6-9]|2[0-9]|3[01])\.|169\.254)/

MATCH_MAC_ADDR = /^\s*(([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2})|([[0-9a-fA-F]{2}]{6})\s*$/i

##
#
# Serialization
Expand Down Expand Up @@ -132,6 +134,21 @@ def self.is_ipv6?(addr)
( addr =~ MATCH_IPV6 ) ? true : false
end

#
# Determine whether this is a MAC address
#
def self.is_mac_addr?(addr)
( addr =~ MATCH_MAC_ADDR) ? true : false
end

#
# Determine whether this is an IP address at all
# Check for v4 (less expensive), v6, else false
#
def self.is_ip_addr?(addr)
self.is_ipv4?(addr) ? true : self.is_ipv6?(addr) ? true : false
end

#
# Checks to see if the supplied address is in "dotted" form
#
Expand Down

0 comments on commit bdbdd27

Please sign in to comment.