rex-socket 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rex/socket.rb +29 -25
- data/lib/rex/socket/version.rb +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92ddd973eb7d16ebd11f040c398d294c62f8caf3
|
4
|
+
data.tar.gz: 59c01a8084132ba7df79382a23ff6ab835a5480e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d5161ad095c421332a0180bd18985d64bf7dc2abb719dce49a442b10bc8a7d5a976c34f18d5882969341c321b6af87328c52daed44fd0ce6cf2153b45e52b02
|
7
|
+
data.tar.gz: 35eb1b361afd7e6df0def370c54e6539f0619ff2f820193b3628595d7671e2abc6c7a42694a071195659f06d97791b2dc44fc15a40ee9a2e161426fbdbf86d9e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/rex/socket.rb
CHANGED
@@ -88,13 +88,14 @@ module Socket
|
|
88
88
|
|
89
89
|
MATCH_IPV4_PRIVATE = /^\s*(?:10\.|192\.168|172.(?:1[6-9]|2[0-9]|3[01])\.|169\.254)/
|
90
90
|
|
91
|
+
MATCH_MAC_ADDR = /^\s*(([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2})|([[0-9a-fA-F]{2}]{6})\s*$/i
|
92
|
+
|
91
93
|
##
|
92
94
|
#
|
93
95
|
# Serialization
|
94
96
|
#
|
95
97
|
##
|
96
98
|
|
97
|
-
|
98
99
|
# Cache our IPv6 support flag
|
99
100
|
@@support_ipv6 = nil
|
100
101
|
|
@@ -122,27 +123,36 @@ module Socket
|
|
122
123
|
# Determine whether this is an IPv4 address
|
123
124
|
#
|
124
125
|
def self.is_ipv4?(addr)
|
125
|
-
|
126
|
+
addr =~ MATCH_IPV4 ? true : false
|
126
127
|
end
|
127
128
|
|
128
129
|
#
|
129
130
|
# Determine whether this is an IPv6 address
|
130
131
|
#
|
131
132
|
def self.is_ipv6?(addr)
|
132
|
-
|
133
|
+
addr =~ MATCH_IPV6 ? true : false
|
133
134
|
end
|
134
135
|
|
135
136
|
#
|
136
|
-
#
|
137
|
+
# Determine whether this is a MAC address
|
137
138
|
#
|
138
|
-
def self.
|
139
|
-
|
140
|
-
|
139
|
+
def self.is_mac_addr?(addr)
|
140
|
+
addr =~ MATCH_MAC_ADDR ? true : false
|
141
|
+
end
|
141
142
|
|
142
|
-
|
143
|
-
|
143
|
+
#
|
144
|
+
# Determine whether this is an IP address at all
|
145
|
+
# Check for v4 (less expensive), v6, else false
|
146
|
+
#
|
147
|
+
def self.is_ip_addr?(addr)
|
148
|
+
self.is_ipv4?(addr) || self.is_ipv6?(addr)
|
149
|
+
end
|
144
150
|
|
145
|
-
|
151
|
+
#
|
152
|
+
# Checks to see if the supplied address is in "dotted" form
|
153
|
+
#
|
154
|
+
def self.dotted_ip?(addr)
|
155
|
+
(support_ipv6? && addr =~ MATCH_IPV6) || (addr =~ MATCH_IPV4)
|
146
156
|
end
|
147
157
|
|
148
158
|
#
|
@@ -150,11 +160,7 @@ module Socket
|
|
150
160
|
# RFC5735/RFC3927
|
151
161
|
#
|
152
162
|
def self.is_internal?(addr)
|
153
|
-
|
154
|
-
addr =~ MATCH_IPV4_PRIVATE
|
155
|
-
else
|
156
|
-
false
|
157
|
-
end
|
163
|
+
self.dotted_ip?(addr) && addr =~ MATCH_IPV4_PRIVATE
|
158
164
|
end
|
159
165
|
|
160
166
|
# Get the first address returned by a DNS lookup for +hostname+.
|
@@ -176,7 +182,7 @@ module Socket
|
|
176
182
|
# @param hostname [String] A hostname or ASCII IP address
|
177
183
|
# @return [Array<String>]
|
178
184
|
def self.getaddresses(hostname, accept_ipv6 = true)
|
179
|
-
if hostname =~ MATCH_IPV4
|
185
|
+
if hostname =~ MATCH_IPV4 || (accept_ipv6 && hostname =~ MATCH_IPV6)
|
180
186
|
return [hostname]
|
181
187
|
end
|
182
188
|
|
@@ -212,7 +218,7 @@ module Socket
|
|
212
218
|
# on Windows.
|
213
219
|
#
|
214
220
|
def self.gethostbyname(host)
|
215
|
-
if
|
221
|
+
if is_ipv4?(host)
|
216
222
|
return [ host, [], 2, host.split('.').map{ |c| c.to_i }.pack("C4") ]
|
217
223
|
end
|
218
224
|
|
@@ -230,8 +236,7 @@ module Socket
|
|
230
236
|
# address family
|
231
237
|
#
|
232
238
|
def self.to_sockaddr(ip, port)
|
233
|
-
|
234
|
-
if (ip == '::ffff:0.0.0.0')
|
239
|
+
if ip == '::ffff:0.0.0.0'
|
235
240
|
ip = support_ipv6?() ? '::' : '0.0.0.0'
|
236
241
|
end
|
237
242
|
|
@@ -245,7 +250,7 @@ module Socket
|
|
245
250
|
def self.from_sockaddr(saddr)
|
246
251
|
port, host = ::Socket::unpack_sockaddr_in(saddr)
|
247
252
|
af = ::Socket::AF_INET
|
248
|
-
if
|
253
|
+
if support_ipv6?() && is_ipv6?(host)
|
249
254
|
af = ::Socket::AF_INET6
|
250
255
|
end
|
251
256
|
return [ af, host, port ]
|
@@ -471,7 +476,6 @@ module Socket
|
|
471
476
|
# lame kid way of doing it.
|
472
477
|
#
|
473
478
|
def self.net2bitmask(netmask)
|
474
|
-
|
475
479
|
nmask = resolv_nbo(netmask)
|
476
480
|
imask = addr_ntoi(nmask)
|
477
481
|
bits = 32
|
@@ -751,8 +755,8 @@ module Socket
|
|
751
755
|
def peerinfo
|
752
756
|
if (pi = getpeername_as_array)
|
753
757
|
return pi[1] + ':' + pi[2].to_s
|
754
|
-
end
|
755
|
-
end
|
758
|
+
end
|
759
|
+
end
|
756
760
|
|
757
761
|
#
|
758
762
|
# Returns local information (host + port) in host:port format.
|
@@ -760,8 +764,8 @@ module Socket
|
|
760
764
|
def localinfo
|
761
765
|
if (pi = getlocalname)
|
762
766
|
return pi[1] + ':' + pi[2].to_s
|
763
|
-
end
|
764
|
-
end
|
767
|
+
end
|
768
|
+
end
|
765
769
|
|
766
770
|
#
|
767
771
|
# Returns a string that indicates the type of the socket, such as 'tcp'.
|
data/lib/rex/socket/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rex-socket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Maloney
|
@@ -88,7 +88,7 @@ cert_chain:
|
|
88
88
|
G+Hmcg1v810agasPdoydE0RTVZgEOOMoQ07qu7JFXVWZ9ZQpHT7qJATWL/b2csFG
|
89
89
|
8mVuTXnyJOKRJA==
|
90
90
|
-----END CERTIFICATE-----
|
91
|
-
date: 2017-
|
91
|
+
date: 2017-06-25 00:00:00.000000000 Z
|
92
92
|
dependencies:
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: bundler
|
metadata.gz.sig
CHANGED
Binary file
|