ronin-support 1.0.5 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +36 -0
- data/ChangeLog.md +125 -1
- data/README.md +5 -1
- data/lib/ronin/support/archive/core_ext/file.rb +1 -1
- data/lib/ronin/support/archive/core_ext.rb +1 -1
- data/lib/ronin/support/archive/mixin.rb +1 -1
- data/lib/ronin/support/archive/tar/reader.rb +1 -1
- data/lib/ronin/support/archive/tar/writer.rb +1 -1
- data/lib/ronin/support/archive/tar.rb +1 -1
- data/lib/ronin/support/archive/zip/reader/entry.rb +1 -1
- data/lib/ronin/support/archive/zip/reader/statistics.rb +1 -1
- data/lib/ronin/support/archive/zip/reader.rb +1 -1
- data/lib/ronin/support/archive/zip/writer.rb +1 -1
- data/lib/ronin/support/archive/zip.rb +1 -1
- data/lib/ronin/support/archive.rb +1 -1
- data/lib/ronin/support/binary/array.rb +1 -1
- data/lib/ronin/support/binary/bit_flip/core_ext/integer.rb +1 -1
- data/lib/ronin/support/binary/bit_flip/core_ext/string.rb +1 -1
- data/lib/ronin/support/binary/bit_flip/core_ext.rb +1 -1
- data/lib/ronin/support/binary/bit_flip.rb +1 -1
- data/lib/ronin/support/binary/buffer.rb +1 -1
- data/lib/ronin/support/binary/byte_slice.rb +1 -1
- data/lib/ronin/support/binary/core_ext/array.rb +1 -1
- data/lib/ronin/support/binary/core_ext/float.rb +3 -2
- data/lib/ronin/support/binary/core_ext/integer.rb +3 -2
- data/lib/ronin/support/binary/core_ext/io.rb +1 -1
- data/lib/ronin/support/binary/core_ext/string.rb +1 -1
- data/lib/ronin/support/binary/core_ext.rb +1 -1
- data/lib/ronin/support/binary/cstring.rb +1 -1
- data/lib/ronin/support/binary/ctypes/aggregate_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/arm/big_endian.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/arm.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/arm64/big_endian.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/arm64.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/mips/little_endian.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/mips.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/mips64/little_endian.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/mips64.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/ppc.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/ppc64.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/x86.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch/x86_64.rb +1 -1
- data/lib/ronin/support/binary/ctypes/arch.rb +1 -1
- data/lib/ronin/support/binary/ctypes/array_object_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/array_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/big_endian.rb +1 -1
- data/lib/ronin/support/binary/ctypes/char_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/char_types.rb +1 -1
- data/lib/ronin/support/binary/ctypes/enum_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/float32_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/float64_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/float_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/int16_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/int32_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/int64_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/int8_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/int_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/little_endian.rb +1 -1
- data/lib/ronin/support/binary/ctypes/mixin.rb +11 -5
- data/lib/ronin/support/binary/ctypes/native.rb +1 -1
- data/lib/ronin/support/binary/ctypes/network.rb +1 -1
- data/lib/ronin/support/binary/ctypes/object_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/android.rb +39 -0
- data/lib/ronin/support/binary/ctypes/os/apple_ios.rb +39 -0
- data/lib/ronin/support/binary/ctypes/os/bsd.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/freebsd.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/linux.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/macos.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/netbsd.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/openbsd.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/unix.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os/windows.rb +1 -1
- data/lib/ronin/support/binary/ctypes/os.rb +8 -3
- data/lib/ronin/support/binary/ctypes/scalar_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/string_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/struct_object_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/struct_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/type_resolver.rb +7 -3
- data/lib/ronin/support/binary/ctypes/uint16_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/uint32_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/uint64_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/uint8_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/uint_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/unbounded_array_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/union_object_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes/union_type.rb +1 -1
- data/lib/ronin/support/binary/ctypes.rb +16 -10
- data/lib/ronin/support/binary/memory.rb +1 -1
- data/lib/ronin/support/binary/packet.rb +1 -1
- data/lib/ronin/support/binary/stack.rb +1 -1
- data/lib/ronin/support/binary/stream/methods.rb +1 -1
- data/lib/ronin/support/binary/stream.rb +1 -1
- data/lib/ronin/support/binary/struct/member.rb +1 -1
- data/lib/ronin/support/binary/struct.rb +3 -2
- data/lib/ronin/support/binary/template.rb +1 -1
- data/lib/ronin/support/binary/unhexdump/core_ext/file.rb +1 -1
- data/lib/ronin/support/binary/unhexdump/core_ext/string.rb +1 -1
- data/lib/ronin/support/binary/unhexdump/core_ext.rb +1 -1
- data/lib/ronin/support/binary/unhexdump/parser.rb +1 -1
- data/lib/ronin/support/binary/unhexdump.rb +1 -1
- data/lib/ronin/support/binary/union.rb +1 -1
- data/lib/ronin/support/binary.rb +1 -1
- data/lib/ronin/support/cli/ansi.rb +1 -1
- data/lib/ronin/support/cli/io_shell/core_ext/io.rb +1 -1
- data/lib/ronin/support/cli/io_shell/core_ext.rb +1 -1
- data/lib/ronin/support/cli/io_shell.rb +1 -1
- data/lib/ronin/support/cli/printing.rb +1 -1
- data/lib/ronin/support/cli.rb +1 -1
- data/lib/ronin/support/compression/core_ext/file.rb +1 -1
- data/lib/ronin/support/compression/core_ext/string.rb +1 -1
- data/lib/ronin/support/compression/core_ext.rb +1 -1
- data/lib/ronin/support/compression/gzip/reader.rb +1 -1
- data/lib/ronin/support/compression/gzip/writer.rb +1 -1
- data/lib/ronin/support/compression/gzip.rb +1 -1
- data/lib/ronin/support/compression/mixin.rb +1 -1
- data/lib/ronin/support/compression/zlib.rb +1 -1
- data/lib/ronin/support/compression.rb +1 -1
- data/lib/ronin/support/core_ext/enumerable.rb +1 -1
- data/lib/ronin/support/core_ext/file.rb +1 -1
- data/lib/ronin/support/core_ext/integer.rb +1 -1
- data/lib/ronin/support/core_ext/ipaddr.rb +1 -1
- data/lib/ronin/support/core_ext/kernel.rb +1 -1
- data/lib/ronin/support/core_ext/string.rb +1 -1
- data/lib/ronin/support/core_ext.rb +1 -1
- data/lib/ronin/support/crypto/cert.rb +50 -8
- data/lib/ronin/support/crypto/cert_chain.rb +1 -1
- data/lib/ronin/support/crypto/cipher/aes.rb +1 -1
- data/lib/ronin/support/crypto/cipher/aes128.rb +1 -1
- data/lib/ronin/support/crypto/cipher/aes256.rb +1 -1
- data/lib/ronin/support/crypto/cipher.rb +1 -1
- data/lib/ronin/support/crypto/core_ext/file.rb +1 -1
- data/lib/ronin/support/crypto/core_ext/string.rb +1 -1
- data/lib/ronin/support/crypto/core_ext.rb +1 -1
- data/lib/ronin/support/crypto/hmac.rb +1 -1
- data/lib/ronin/support/crypto/key/dh.rb +1 -1
- data/lib/ronin/support/crypto/key/dsa.rb +1 -1
- data/lib/ronin/support/crypto/key/ec.rb +25 -1
- data/lib/ronin/support/crypto/key/methods.rb +1 -1
- data/lib/ronin/support/crypto/key/rsa.rb +1 -1
- data/lib/ronin/support/crypto/key.rb +48 -4
- data/lib/ronin/support/crypto/mixin.rb +1 -1
- data/lib/ronin/support/crypto/openssl.rb +1 -1
- data/lib/ronin/support/crypto.rb +1 -1
- data/lib/ronin/support/encoding/base16/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/base16/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/base16.rb +1 -1
- data/lib/ronin/support/encoding/base32/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/base32/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/base32.rb +1 -1
- data/lib/ronin/support/encoding/base36/core_ext/integer.rb +43 -0
- data/lib/ronin/support/encoding/base36/core_ext/string.rb +43 -0
- data/lib/ronin/support/encoding/base36/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/base36.rb +67 -0
- data/lib/ronin/support/encoding/base62/core_ext/integer.rb +43 -0
- data/lib/ronin/support/encoding/base62/core_ext/string.rb +43 -0
- data/lib/ronin/support/encoding/base62/core_ext.rb +20 -0
- data/lib/ronin/support/encoding/base62.rb +93 -0
- data/lib/ronin/support/encoding/base64/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/base64/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/base64.rb +3 -3
- data/lib/ronin/support/encoding/c/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/c/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/c/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/c.rb +1 -1
- data/lib/ronin/support/encoding/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/hex/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/hex/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/hex/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/hex.rb +1 -1
- data/lib/ronin/support/encoding/html/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/html/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/html/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/html.rb +1 -1
- data/lib/ronin/support/encoding/http/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/http/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/http/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/http.rb +1 -1
- data/lib/ronin/support/encoding/js/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/js/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/js/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/js.rb +1 -1
- data/lib/ronin/support/encoding/powershell/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/powershell/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/powershell/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/powershell.rb +1 -1
- data/lib/ronin/support/encoding/punycode/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/punycode/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/punycode.rb +1 -1
- data/lib/ronin/support/encoding/quoted_printable/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/quoted_printable/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/quoted_printable.rb +1 -1
- data/lib/ronin/support/encoding/ruby/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/ruby/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/ruby.rb +1 -1
- data/lib/ronin/support/encoding/shell/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/shell/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/shell/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/shell.rb +1 -1
- data/lib/ronin/support/encoding/smtp.rb +1 -1
- data/lib/ronin/support/encoding/sql/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/sql/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/sql.rb +1 -1
- data/lib/ronin/support/encoding/uri/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/uri/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/uri/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/uri.rb +1 -1
- data/lib/ronin/support/encoding/uuencoding/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/uuencoding/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/uuencoding.rb +1 -1
- data/lib/ronin/support/encoding/xml/core_ext/integer.rb +1 -1
- data/lib/ronin/support/encoding/xml/core_ext/string.rb +1 -1
- data/lib/ronin/support/encoding/xml/core_ext.rb +1 -1
- data/lib/ronin/support/encoding/xml.rb +1 -1
- data/lib/ronin/support/encoding.rb +7 -1
- data/lib/ronin/support/home.rb +1 -1
- data/lib/ronin/support/mixin.rb +1 -1
- data/lib/ronin/support/network/asn/dns_record.rb +1 -1
- data/lib/ronin/support/network/asn/list.rb +1 -1
- data/lib/ronin/support/network/asn/record.rb +1 -1
- data/lib/ronin/support/network/asn/record_set.rb +1 -1
- data/lib/ronin/support/network/asn.rb +1 -1
- data/lib/ronin/support/network/core_ext.rb +1 -1
- data/lib/ronin/support/network/dns/idn.rb +1 -1
- data/lib/ronin/support/network/dns/mixin.rb +1 -1
- data/lib/ronin/support/network/dns/resolver.rb +1 -1
- data/lib/ronin/support/network/dns.rb +1 -1
- data/lib/ronin/support/network/domain.rb +1 -1
- data/lib/ronin/support/network/email_address.rb +1 -1
- data/lib/ronin/support/network/esmtp/mixin.rb +1 -1
- data/lib/ronin/support/network/exceptions.rb +1 -1
- data/lib/ronin/support/network/ftp/mixin.rb +1 -1
- data/lib/ronin/support/network/host.rb +1 -1
- data/lib/ronin/support/network/http/cookie.rb +1 -1
- data/lib/ronin/support/network/http/core_ext/uri/http.rb +1 -1
- data/lib/ronin/support/network/http/core_ext.rb +1 -1
- data/lib/ronin/support/network/http/mixin.rb +42 -1
- data/lib/ronin/support/network/http/request.rb +86 -9
- data/lib/ronin/support/network/http/set_cookie.rb +1 -1
- data/lib/ronin/support/network/http/user_agents.rb +1 -1
- data/lib/ronin/support/network/http.rb +143 -8
- data/lib/ronin/support/network/imap/mixin.rb +1 -1
- data/lib/ronin/support/network/ip/mixin.rb +1 -1
- data/lib/ronin/support/network/ip.rb +42 -1
- data/lib/ronin/support/network/ip_range/cidr.rb +127 -16
- data/lib/ronin/support/network/ip_range/glob.rb +175 -32
- data/lib/ronin/support/network/ip_range/range.rb +37 -22
- data/lib/ronin/support/network/ip_range.rb +147 -23
- data/lib/ronin/support/network/mixin.rb +1 -11
- data/lib/ronin/support/network/packet.rb +1 -1
- data/lib/ronin/support/network/pop3/mixin.rb +6 -3
- data/lib/ronin/support/network/proxy.rb +1 -1
- data/lib/ronin/support/network/public_suffix/list.rb +1 -1
- data/lib/ronin/support/network/public_suffix/suffix.rb +1 -1
- data/lib/ronin/support/network/public_suffix/suffix_set.rb +1 -1
- data/lib/ronin/support/network/public_suffix.rb +1 -1
- data/lib/ronin/support/network/smtp/email.rb +1 -1
- data/lib/ronin/support/network/smtp/mixin.rb +6 -3
- data/lib/ronin/support/network/smtp.rb +1 -1
- data/lib/ronin/support/network/ssl/local_cert.rb +1 -1
- data/lib/ronin/support/network/ssl/local_key.rb +1 -1
- data/lib/ronin/support/network/ssl/mixin.rb +169 -400
- data/lib/ronin/support/network/ssl/openssl.rb +1 -1
- data/lib/ronin/support/network/ssl/proxy.rb +1 -1
- data/lib/ronin/support/network/ssl.rb +592 -13
- data/lib/ronin/support/network/tcp/mixin.rb +1 -1
- data/lib/ronin/support/network/tcp/proxy.rb +1 -1
- data/lib/ronin/support/network/tcp.rb +6 -3
- data/lib/ronin/support/network/telnet/mixin.rb +1 -1
- data/lib/ronin/support/network/telnet.rb +1 -1
- data/lib/ronin/support/network/tld/list.rb +1 -1
- data/lib/ronin/support/network/tld.rb +1 -1
- data/lib/ronin/support/network/tls/mixin.rb +174 -348
- data/lib/ronin/support/network/tls/proxy.rb +1 -1
- data/lib/ronin/support/network/tls.rb +492 -6
- data/lib/ronin/support/network/udp/mixin.rb +1 -1
- data/lib/ronin/support/network/udp/proxy.rb +1 -1
- data/lib/ronin/support/network/udp.rb +6 -3
- data/lib/ronin/support/network/unix/mixin.rb +1 -1
- data/lib/ronin/support/network/wildcard.rb +88 -0
- data/lib/ronin/support/network.rb +1 -1
- data/lib/ronin/support/path.rb +1 -1
- data/lib/ronin/support/text/core_ext/regexp.rb +1 -1
- data/lib/ronin/support/text/core_ext/string.rb +1 -1
- data/lib/ronin/support/text/core_ext.rb +1 -1
- data/lib/ronin/support/text/entropy/core_ext/string.rb +1 -1
- data/lib/ronin/support/text/entropy/core_ext.rb +1 -1
- data/lib/ronin/support/text/entropy.rb +1 -1
- data/lib/ronin/support/text/erb/mixin.rb +1 -1
- data/lib/ronin/support/text/erb.rb +1 -1
- data/lib/ronin/support/text/homoglyph/core_ext/string.rb +1 -1
- data/lib/ronin/support/text/homoglyph/core_ext.rb +1 -1
- data/lib/ronin/support/text/homoglyph/exceptions.rb +1 -1
- data/lib/ronin/support/text/homoglyph/table.rb +1 -1
- data/lib/ronin/support/text/homoglyph.rb +1 -1
- data/lib/ronin/support/text/mixin.rb +1 -1
- data/lib/ronin/support/text/patterns/credentials.rb +1 -1
- data/lib/ronin/support/text/patterns/crypto.rb +1 -1
- data/lib/ronin/support/text/patterns/file_system.rb +1 -1
- data/lib/ronin/support/text/patterns/language.rb +1 -1
- data/lib/ronin/support/text/patterns/network/public_suffix.rb +1 -1
- data/lib/ronin/support/text/patterns/network.rb +1 -1
- data/lib/ronin/support/text/patterns/numeric.rb +1 -1
- data/lib/ronin/support/text/patterns/pii.rb +1 -1
- data/lib/ronin/support/text/patterns/source_code.rb +1 -1
- data/lib/ronin/support/text/patterns.rb +1 -1
- data/lib/ronin/support/text/random/mixin.rb +1 -1
- data/lib/ronin/support/text/random.rb +1 -1
- data/lib/ronin/support/text/typo/core_ext/string.rb +1 -1
- data/lib/ronin/support/text/typo/core_ext.rb +1 -1
- data/lib/ronin/support/text/typo/exceptions.rb +1 -1
- data/lib/ronin/support/text/typo/generator.rb +1 -1
- data/lib/ronin/support/text/typo.rb +1 -1
- data/lib/ronin/support/text.rb +1 -1
- data/lib/ronin/support/version.rb +2 -2
- data/lib/ronin/support.rb +1 -1
- metadata +14 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# Copyright (c) 2006-
|
3
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
4
4
|
#
|
5
5
|
# ronin-support is free software: you can redistribute it and/or modify
|
6
6
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -31,7 +31,6 @@ module Ronin
|
|
31
31
|
# cidr.each { |ip puts }
|
32
32
|
# # 10.0.0.0
|
33
33
|
# # 10.0.0.1
|
34
|
-
# # 10.0.0.2
|
35
34
|
# # ...
|
36
35
|
# # 10.0.0.254
|
37
36
|
# # 10.0.0.255
|
@@ -44,6 +43,49 @@ module Ronin
|
|
44
43
|
|
45
44
|
include Enumerable
|
46
45
|
|
46
|
+
ipv4_octet = /(?:\d{1,2}|1\d{2}|2[1-4]\d|25[0-5])/
|
47
|
+
ipv4_addr = /#{ipv4_octet}(?:\.#{ipv4_octet}){3}/
|
48
|
+
|
49
|
+
# Regular expression that matches IPv4 CIDR ranges.
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
#
|
53
|
+
# @since 1.1.0
|
54
|
+
IPV4_REGEX = %r{\A#{ipv4_addr}(?:/(?:\d|[12]\d|3[0-2]))?\z}
|
55
|
+
|
56
|
+
# Regular expression that matches IPv6 CIDR ranges.
|
57
|
+
#
|
58
|
+
# @api private
|
59
|
+
#
|
60
|
+
# @since 1.1.0
|
61
|
+
IPV6_REGEX = %r{\A(?:
|
62
|
+
(?:[0-9a-fA-F]{1,4}:){6}#{ipv4_addr}|
|
63
|
+
(?:[0-9a-fA-F]{1,4}:){5}[0-9a-fA-F]{1,4}:#{ipv4_addr}|
|
64
|
+
(?:[0-9a-fA-F]{1,4}:){5}:[0-9a-fA-F]{1,4}:#{ipv4_addr}|
|
65
|
+
(?:[0-9a-fA-F]{1,4}:){1,1}(?::[0-9a-fA-F]{1,4}){1,4}:#{ipv4_addr}|
|
66
|
+
(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,3}:#{ipv4_addr}|
|
67
|
+
(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,2}:#{ipv4_addr}|
|
68
|
+
(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,1}:#{ipv4_addr}|
|
69
|
+
:(?::[0-9a-fA-F]{1,4}){1,5}:#{ipv4_addr}|
|
70
|
+
(?:(?:[0-9a-fA-F]{1,4}:){1,5}|:):#{ipv4_addr}|
|
71
|
+
(?:[0-9a-fA-F]{1,4}:){1,1}(?::[0-9a-fA-F]{1,4}){1,6}|
|
72
|
+
(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|
|
73
|
+
(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|
|
74
|
+
(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|
|
75
|
+
(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|
|
76
|
+
(?:[0-9a-fA-F]{1,4}:){1,6}(?::[0-9a-fA-F]{1,4}){1,1}|
|
77
|
+
[0-9a-fA-F]{1,4}(?::[0-9a-fA-F]{1,4}){7}|
|
78
|
+
:(?::[0-9a-fA-F]{1,4}){1,7}|
|
79
|
+
(?:(?:[0-9a-fA-F]{1,4}:){1,7}|:):
|
80
|
+
)(?:/(?:\d{1,2}|1[0-1]\d+|12[0-8]))?\z}x
|
81
|
+
|
82
|
+
# Regular expression to match IP-glob ranges.
|
83
|
+
#
|
84
|
+
# @api private
|
85
|
+
#
|
86
|
+
# @since 1.1.0
|
87
|
+
REGEX = /#{IPV4_REGEX}|#{IPV6_REGEX}/
|
88
|
+
|
47
89
|
# The CIDR IP range string.
|
48
90
|
#
|
49
91
|
# @return [String]
|
@@ -59,12 +101,21 @@ module Ronin
|
|
59
101
|
# The address family for the CIDR range. This is mainly for
|
60
102
|
# backwards compatibility with `IPAddr#initialize`.
|
61
103
|
#
|
104
|
+
# @raise [ArgumentError]
|
105
|
+
# The CIDR range string was not a valid IPv4 or IPv6 CIDR range.
|
106
|
+
#
|
62
107
|
def initialize(string,family=Socket::AF_UNSPEC)
|
108
|
+
unless (string =~ IPV4_REGEX || string =~ IPV6_REGEX)
|
109
|
+
raise(ArgumentError,"invalid CIDR range: #{string.inspect}")
|
110
|
+
end
|
111
|
+
|
63
112
|
super(string,family)
|
64
113
|
|
65
114
|
@string = string
|
66
115
|
end
|
67
116
|
|
117
|
+
alias prefix_address to_string
|
118
|
+
|
68
119
|
#
|
69
120
|
# Alias for {#initialize new}.
|
70
121
|
#
|
@@ -151,8 +202,8 @@ module Ronin
|
|
151
202
|
#
|
152
203
|
# @example
|
153
204
|
# IPRange::CIDR.each('10.0.0.1/24') { |ip| puts ip }
|
205
|
+
# # 10.0.0.0
|
154
206
|
# # 10.0.0.1
|
155
|
-
# # 10.0.0.2
|
156
207
|
# # ...
|
157
208
|
# # 10.0.0.254
|
158
209
|
# # 10.0.0.255
|
@@ -161,6 +212,65 @@ module Ronin
|
|
161
212
|
new(string).each(&block)
|
162
213
|
end
|
163
214
|
|
215
|
+
#
|
216
|
+
# Determines if the given IP belongs to the IP CIDR range.
|
217
|
+
#
|
218
|
+
# @param [IP, IPAddr, String] ip
|
219
|
+
# The IP to test.
|
220
|
+
#
|
221
|
+
# @return [Boolean]
|
222
|
+
# Specifies whether the IP is or is not within the IP CIDR range.
|
223
|
+
#
|
224
|
+
# @since 1.1.0
|
225
|
+
#
|
226
|
+
def include?(ip)
|
227
|
+
ip = IPAddr.new(ip) unless ip.kind_of?(IPAddr)
|
228
|
+
|
229
|
+
family_mask = MASKS[@family]
|
230
|
+
start_addr = @addr
|
231
|
+
end_addr = @addr | (~@mask_addr & family_mask)
|
232
|
+
ip_addr = ip.to_i
|
233
|
+
|
234
|
+
return (ip_addr >= start_addr) && (ip_addr <= end_addr)
|
235
|
+
end
|
236
|
+
|
237
|
+
#
|
238
|
+
# Compares the CIDR range to another IP range.
|
239
|
+
#
|
240
|
+
# @param [Object] other
|
241
|
+
# The other IP range.
|
242
|
+
#
|
243
|
+
# @return [Boolean]
|
244
|
+
#
|
245
|
+
# @since 1.1.0
|
246
|
+
#
|
247
|
+
def ==(other)
|
248
|
+
other.kind_of?(self.class) &&
|
249
|
+
family == other.family &&
|
250
|
+
to_i == other.to_i
|
251
|
+
end
|
252
|
+
|
253
|
+
#
|
254
|
+
# Determines if the given IP range is a sub-set of the IP CIDR range.
|
255
|
+
#
|
256
|
+
# @param [CIDR, Glob, Enumerable<String>] other
|
257
|
+
# The other IP range.
|
258
|
+
#
|
259
|
+
# @return [Boolean]
|
260
|
+
#
|
261
|
+
# @since 1.1.0
|
262
|
+
#
|
263
|
+
def ===(other)
|
264
|
+
case other
|
265
|
+
when CIDR
|
266
|
+
include?(other.first) && include?(other.last)
|
267
|
+
when Enumerable
|
268
|
+
other.all? { |ip| include?(ip) }
|
269
|
+
else
|
270
|
+
false
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
164
274
|
#
|
165
275
|
# Iterates over each IP address that is included in the addresses
|
166
276
|
# netmask. Supports both IPv4 and IPv6 addresses.
|
@@ -174,17 +284,14 @@ module Ronin
|
|
174
284
|
#
|
175
285
|
# @return [self]
|
176
286
|
#
|
177
|
-
# @note
|
178
|
-
# This method will skip IPv4 addresses ending in `.0` or `.255`.
|
179
|
-
#
|
180
287
|
# @example
|
181
288
|
# cidr = IPAddr.new('10.1.1.1/24')
|
182
289
|
# cidr.each { |ip| puts ip }
|
290
|
+
# # 10.0.0.0
|
183
291
|
# # 10.0.0.1
|
184
|
-
# # 10.0.0.2
|
185
292
|
# # ...
|
186
|
-
# # 10.0.0.253
|
187
293
|
# # 10.0.0.254
|
294
|
+
# # 10.0.0.255
|
188
295
|
#
|
189
296
|
def each
|
190
297
|
return enum_for(__method__) unless block_given?
|
@@ -192,14 +299,7 @@ module Ronin
|
|
192
299
|
family_mask = MASKS[@family]
|
193
300
|
|
194
301
|
(0..((~@mask_addr) & family_mask)).each do |i|
|
195
|
-
|
196
|
-
|
197
|
-
# skip IPv4 addresses ending in .0 or .255
|
198
|
-
if (ipv4? && ((ip_uint & 0xff) == 0 || (ip_uint & 0xff) == 0xff))
|
199
|
-
next
|
200
|
-
end
|
201
|
-
|
202
|
-
yield _to_string(ip_uint)
|
302
|
+
yield _to_string(@addr | i)
|
203
303
|
end
|
204
304
|
|
205
305
|
return self
|
@@ -223,6 +323,17 @@ module Ronin
|
|
223
323
|
_to_string(@addr | ~@mask_addr)
|
224
324
|
end
|
225
325
|
|
326
|
+
#
|
327
|
+
# Calculates the size of the CIDR range.
|
328
|
+
#
|
329
|
+
# @return [Integer]
|
330
|
+
#
|
331
|
+
# @since 1.1.0
|
332
|
+
#
|
333
|
+
def size
|
334
|
+
2**(SIZES.fetch(family) - prefix)
|
335
|
+
end
|
336
|
+
|
226
337
|
#
|
227
338
|
# Converts the CIDR range back into a String.
|
228
339
|
#
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# Copyright (c) 2006-
|
3
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
4
4
|
#
|
5
5
|
# ronin-support is free software: you can redistribute it and/or modify
|
6
6
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -29,23 +29,23 @@ module Ronin
|
|
29
29
|
#
|
30
30
|
# ip_range = IPRange::Glob.new('10.0.1-3.*/24')
|
31
31
|
# ip_range.each { |ip| puts ip }
|
32
|
+
# # 10.0.1.0
|
32
33
|
# # 10.0.1.1
|
33
|
-
# # 10.0.1.2
|
34
34
|
# # ...
|
35
|
-
# # 10.0.1.253
|
36
35
|
# # 10.0.1.254
|
36
|
+
# # 10.0.1.255
|
37
37
|
# # ...
|
38
|
+
# # 10.0.2.0
|
38
39
|
# # 10.0.2.1
|
39
|
-
# # 10.0.2.2
|
40
40
|
# # ...
|
41
|
-
# # 10.0.2.253
|
42
41
|
# # 10.0.2.254
|
42
|
+
# # 10.0.2.255
|
43
43
|
# # ...
|
44
|
+
# # 10.0.3.0
|
44
45
|
# # 10.0.3.1
|
45
|
-
# # 10.0.3.2
|
46
46
|
# # ...
|
47
|
-
# # 10.0.3.253
|
48
47
|
# # 10.0.3.254
|
48
|
+
# # 10.0.3.255
|
49
49
|
#
|
50
50
|
# @api public
|
51
51
|
#
|
@@ -55,6 +55,55 @@ module Ronin
|
|
55
55
|
|
56
56
|
include Enumerable
|
57
57
|
|
58
|
+
ipv4_octet = /(?:\d{1,2}|1\d{2}|2[1-4]\d|25[0-5])/
|
59
|
+
ipv4_octet_range = /#{ipv4_octet}(?:-#{ipv4_octet})?/
|
60
|
+
ipv4_octet_list = /(?:#{ipv4_octet_range}(?:,#{ipv4_octet_range})*|\*)/
|
61
|
+
ipv4_addr = /#{ipv4_octet_list}(?:\.#{ipv4_octet_list}){3}/
|
62
|
+
|
63
|
+
# Regular expression that matches IPv4-glob ranges.
|
64
|
+
#
|
65
|
+
# @api private
|
66
|
+
#
|
67
|
+
# @since 1.1.0
|
68
|
+
IPV4_REGEX = /\A#{ipv4_addr}\z/
|
69
|
+
|
70
|
+
ipv6_octet = /[0-9a-fA-F]{1,4}/
|
71
|
+
ipv6_octet_range = /#{ipv6_octet}(?:-#{ipv6_octet})?/
|
72
|
+
ipv6_octet_list = /(?:#{ipv6_octet_range}(?:,#{ipv6_octet_range})*|\*)/
|
73
|
+
|
74
|
+
# Regular expression that matches IPv6-glob ranges.
|
75
|
+
#
|
76
|
+
# @api private
|
77
|
+
#
|
78
|
+
# @since 1.1.0
|
79
|
+
IPV6_REGEX = /\A(?:
|
80
|
+
(?:#{ipv6_octet_list}:){6}#{ipv4_addr}|
|
81
|
+
(?:#{ipv6_octet_list}:){5}#{ipv6_octet_list}:#{ipv4_addr}|
|
82
|
+
(?:#{ipv6_octet_list}:){5}:#{ipv6_octet_list}:#{ipv4_addr}|
|
83
|
+
(?:#{ipv6_octet_list}:){1,1}(?::#{ipv6_octet_list}){1,4}:#{ipv4_addr}|
|
84
|
+
(?:#{ipv6_octet_list}:){1,2}(?::#{ipv6_octet_list}){1,3}:#{ipv4_addr}|
|
85
|
+
(?:#{ipv6_octet_list}:){1,3}(?::#{ipv6_octet_list}){1,2}:#{ipv4_addr}|
|
86
|
+
(?:#{ipv6_octet_list}:){1,4}(?::#{ipv6_octet_list}){1,1}:#{ipv4_addr}|
|
87
|
+
:(?::#{ipv6_octet_list}){1,5}:#{ipv4_addr}|
|
88
|
+
(?:(?:#{ipv6_octet_list}:){1,5}|:):#{ipv4_addr}|
|
89
|
+
(?:#{ipv6_octet_list}:){1,1}(?::#{ipv6_octet_list}){1,6}|
|
90
|
+
(?:#{ipv6_octet_list}:){1,2}(?::#{ipv6_octet_list}){1,5}|
|
91
|
+
(?:#{ipv6_octet_list}:){1,3}(?::#{ipv6_octet_list}){1,4}|
|
92
|
+
(?:#{ipv6_octet_list}:){1,4}(?::#{ipv6_octet_list}){1,3}|
|
93
|
+
(?:#{ipv6_octet_list}:){1,5}(?::#{ipv6_octet_list}){1,2}|
|
94
|
+
(?:#{ipv6_octet_list}:){1,6}(?::#{ipv6_octet_list}){1,1}|
|
95
|
+
#{ipv6_octet_list}(?::#{ipv6_octet_list}){7}|
|
96
|
+
:(?::#{ipv6_octet_list}){1,7}|
|
97
|
+
(?:(?:#{ipv6_octet_list}:){1,7}|:):
|
98
|
+
)\z/x
|
99
|
+
|
100
|
+
# Regular expression to match IP-glob ranges.
|
101
|
+
#
|
102
|
+
# @api private
|
103
|
+
#
|
104
|
+
# @since 1.1.0
|
105
|
+
REGEX = /#{IPV4_REGEX}|#{IPV6_REGEX}/
|
106
|
+
|
58
107
|
# The IP glob string.
|
59
108
|
#
|
60
109
|
# @return [String]
|
@@ -66,27 +115,36 @@ module Ronin
|
|
66
115
|
# @param [String] string
|
67
116
|
# The IP-glob string to parse.
|
68
117
|
#
|
118
|
+
# @raise [ArgumentError]
|
119
|
+
# The IP-glob string was neither a valid IPv4 or IPv6 glob address.
|
120
|
+
#
|
69
121
|
def initialize(string)
|
70
122
|
@string = string
|
71
123
|
|
72
|
-
|
73
|
-
|
74
|
-
@separator = ':'
|
75
|
-
@base = 16
|
76
|
-
@formatter = method(:format_ipv6_address)
|
77
|
-
else # IPv4
|
124
|
+
case string
|
125
|
+
when IPV4_REGEX
|
78
126
|
@version = 4
|
79
|
-
@separator = '.'
|
80
127
|
@base = 10
|
81
128
|
@formatter = method(:format_ipv4_address)
|
129
|
+
|
130
|
+
separator = '.'
|
131
|
+
octet_range = (0..255)
|
132
|
+
when IPV6_REGEX
|
133
|
+
@version = 6
|
134
|
+
@base = 16
|
135
|
+
@formatter = method(:format_ipv6_address)
|
136
|
+
|
137
|
+
separator = ':'
|
138
|
+
octet_range = (0..0xffff)
|
139
|
+
else
|
140
|
+
raise(ArgumentError,"invalid IP-glob range: #{string.inspect}")
|
82
141
|
end
|
83
142
|
|
84
|
-
@ranges =
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
else [segment]
|
143
|
+
@ranges = string.split(separator).map do |segment|
|
144
|
+
if segment == '*' then octet_range
|
145
|
+
elsif segment.include?(',') then parse_list(segment)
|
146
|
+
elsif segment.include?('-') then parse_range(segment)
|
147
|
+
else [segment]
|
90
148
|
end
|
91
149
|
end
|
92
150
|
end
|
@@ -123,23 +181,23 @@ module Ronin
|
|
123
181
|
#
|
124
182
|
# @example Enumerate through a IPv4 glob range:
|
125
183
|
# IPRange::Glob.each('10.0.1-3.*') { |ip| puts ip }
|
184
|
+
# # 10.0.1.0
|
126
185
|
# # 10.0.1.1
|
127
|
-
# # 10.0.1.2
|
128
186
|
# # ...
|
129
|
-
# # 10.0.1.253
|
130
187
|
# # 10.0.1.254
|
188
|
+
# # 10.0.1.255
|
131
189
|
# # ...
|
190
|
+
# # 10.0.2.0
|
132
191
|
# # 10.0.2.1
|
133
|
-
# # 10.0.2.2
|
134
192
|
# # ...
|
135
|
-
# # 10.0.2.253
|
136
193
|
# # 10.0.2.254
|
194
|
+
# # 10.0.2.255
|
137
195
|
# # ...
|
196
|
+
# # 10.0.3.0
|
138
197
|
# # 10.0.3.1
|
139
|
-
# # 10.0.3.2
|
140
198
|
# # ...
|
141
|
-
# # 10.0.3.253
|
142
199
|
# # 10.0.3.254
|
200
|
+
# # 10.0.3.255
|
143
201
|
#
|
144
202
|
# @example Enumerate through a globbed IPv6 range:
|
145
203
|
# IPRange::Glob.each('::ff::02-0a::c3') { |ip| puts ip }
|
@@ -166,6 +224,54 @@ module Ronin
|
|
166
224
|
@version == 6
|
167
225
|
end
|
168
226
|
|
227
|
+
#
|
228
|
+
# Determines whether the IP address exists within the IP range.
|
229
|
+
#
|
230
|
+
# @param [IP, IPAddr, String] ip
|
231
|
+
# The IP address to check.
|
232
|
+
#
|
233
|
+
# @return [Boolean]
|
234
|
+
# Indicates whether the IP address exists within the IP range.
|
235
|
+
#
|
236
|
+
# @since 1.1.0
|
237
|
+
#
|
238
|
+
def include?(ip)
|
239
|
+
super(ip.to_s)
|
240
|
+
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# Compares the IP glob range to another IP range.
|
244
|
+
#
|
245
|
+
# @param [Object] other
|
246
|
+
# The other IP range.
|
247
|
+
#
|
248
|
+
# @return [Boolean]
|
249
|
+
#
|
250
|
+
# @since 1.1.0
|
251
|
+
#
|
252
|
+
def ==(other)
|
253
|
+
other.kind_of?(self.class) && @string == other.string
|
254
|
+
end
|
255
|
+
|
256
|
+
#
|
257
|
+
# Determines if the given IP range is a sub-set of the IP CIDR range.
|
258
|
+
#
|
259
|
+
# @param [Glob, CIDR, Enumerable<String>] other
|
260
|
+
# The other IP range.
|
261
|
+
#
|
262
|
+
# @return [Boolean]
|
263
|
+
#
|
264
|
+
# @since 1.1.0
|
265
|
+
#
|
266
|
+
def ===(other)
|
267
|
+
case other
|
268
|
+
when Enumerable
|
269
|
+
other.all? { |ip| include?(ip) }
|
270
|
+
else
|
271
|
+
false
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
169
275
|
#
|
170
276
|
# Enumerates over the IP-glob range.
|
171
277
|
#
|
@@ -181,23 +287,23 @@ module Ronin
|
|
181
287
|
# @example Enumerate through a IPv4 glob range:
|
182
288
|
# ip_range = IPRange::Glob.new('10.0.1-3.*')
|
183
289
|
# ip_range.each { |ip| puts ip }
|
290
|
+
# # 10.0.1.0
|
184
291
|
# # 10.0.1.1
|
185
|
-
# # 10.0.1.2
|
186
292
|
# # ...
|
187
|
-
# # 10.0.1.253
|
188
293
|
# # 10.0.1.254
|
294
|
+
# # 10.0.1.255
|
189
295
|
# # ...
|
296
|
+
# # 10.0.2.0
|
190
297
|
# # 10.0.2.1
|
191
|
-
# # 10.0.2.2
|
192
298
|
# # ...
|
193
|
-
# # 10.0.2.253
|
194
299
|
# # 10.0.2.254
|
300
|
+
# # 10.0.2.255
|
195
301
|
# # ...
|
302
|
+
# # 10.0.3.0
|
196
303
|
# # 10.0.3.1
|
197
|
-
# # 10.0.3.2
|
198
304
|
# # ...
|
199
|
-
# # 10.0.3.253
|
200
305
|
# # 10.0.3.254
|
306
|
+
# # 10.0.3.255
|
201
307
|
#
|
202
308
|
# @example Enumerate through a globbed IPv6 range:
|
203
309
|
# ip_range = IPRange::Glob.new('::ff::02-0a::c3')
|
@@ -214,6 +320,43 @@ module Ronin
|
|
214
320
|
return self
|
215
321
|
end
|
216
322
|
|
323
|
+
#
|
324
|
+
# The first address in the IP glob range.
|
325
|
+
#
|
326
|
+
# @return [String]
|
327
|
+
# The first IP address in the IP glob range.
|
328
|
+
#
|
329
|
+
# @since 1.1.0
|
330
|
+
#
|
331
|
+
def first
|
332
|
+
@formatter.call(@ranges.map(&:first))
|
333
|
+
end
|
334
|
+
|
335
|
+
#
|
336
|
+
# The last address in the IP glob range.
|
337
|
+
#
|
338
|
+
# @return [String]
|
339
|
+
# The last IP address in the IP glob range.
|
340
|
+
#
|
341
|
+
# @since 1.1.0
|
342
|
+
#
|
343
|
+
def last
|
344
|
+
@formatter.call(@ranges.map(&:last))
|
345
|
+
end
|
346
|
+
|
347
|
+
#
|
348
|
+
# Calculates the size of the IP glob range.
|
349
|
+
#
|
350
|
+
# @return [Integer]
|
351
|
+
#
|
352
|
+
# @since 1.1.0
|
353
|
+
#
|
354
|
+
def size
|
355
|
+
@ranges.reduce(1) do |total,parts|
|
356
|
+
total * parts.size
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
217
360
|
#
|
218
361
|
# Converts the IP-glob range back into a String.
|
219
362
|
#
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
#
|
3
|
-
# Copyright (c) 2006-
|
3
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
4
4
|
#
|
5
5
|
# ronin-support is free software: you can redistribute it and/or modify
|
6
6
|
# it under the terms of the GNU Lesser General Public License as published
|
@@ -145,7 +145,7 @@ module Ronin
|
|
145
145
|
#
|
146
146
|
# Determines if the given IP belongs to the ASN IP range.
|
147
147
|
#
|
148
|
-
# @param [IPAddr, String] ip
|
148
|
+
# @param [IP, IPAddr, String] ip
|
149
149
|
# The IP to test.
|
150
150
|
#
|
151
151
|
# @return [Boolean]
|
@@ -171,26 +171,14 @@ module Ronin
|
|
171
171
|
# @return [Enumerator]
|
172
172
|
# If no block is given, an Enumerator will be returned.
|
173
173
|
#
|
174
|
-
# @note
|
175
|
-
# This method will skip IPv4 addresses ending in `.0` or `.255`.
|
176
|
-
#
|
177
174
|
# @example
|
178
|
-
# range = IPRange::Range.new('1.1.1.
|
175
|
+
# range = IPRange::Range.new('1.1.1.1','1.1.3.42')
|
179
176
|
# range.each { |ip| puts ip }
|
180
177
|
# # 1.1.1.1
|
181
178
|
# # 1.1.1.2
|
182
179
|
# # ...
|
183
|
-
# # 1.1.
|
184
|
-
# # 1.1.
|
185
|
-
#
|
186
|
-
# @example
|
187
|
-
# range IPRange::Range.new('1.1.1.100','1.1.3.200')
|
188
|
-
# range.each { |ip| puts ip }
|
189
|
-
# # 1.1.1.100
|
190
|
-
# # 1.1.1.101
|
191
|
-
# # ...
|
192
|
-
# # 1.1.3.199
|
193
|
-
# # 1.1.3.200
|
180
|
+
# # 1.1.3.41
|
181
|
+
# # 1.1.3.42
|
194
182
|
#
|
195
183
|
def each
|
196
184
|
return enum_for(__method__) unless block_given?
|
@@ -198,11 +186,6 @@ module Ronin
|
|
198
186
|
ipaddr = @begin.clone
|
199
187
|
|
200
188
|
(@begin_uint..@end_uint).each do |ip_uint|
|
201
|
-
# skip IPv4 addresses ending in .0 or .255
|
202
|
-
if (ipv4? && ((ip_uint & 0xff) == 0 || (ip_uint & 0xff) == 0xff))
|
203
|
-
next
|
204
|
-
end
|
205
|
-
|
206
189
|
ipaddr.send(:set,ip_uint)
|
207
190
|
yield ipaddr.to_s
|
208
191
|
end
|
@@ -224,6 +207,38 @@ module Ronin
|
|
224
207
|
self.end == other.end
|
225
208
|
end
|
226
209
|
|
210
|
+
#
|
211
|
+
# Determines if the given IP range is a sub-set of the IP range.
|
212
|
+
#
|
213
|
+
# @param [IPRange::Range, CIDR, Glob, Enumerable<String>] other
|
214
|
+
# The other IP range.
|
215
|
+
#
|
216
|
+
# @return [Boolean]
|
217
|
+
#
|
218
|
+
# @since 1.1.0
|
219
|
+
#
|
220
|
+
def ===(other)
|
221
|
+
case other
|
222
|
+
when IPRange::Range
|
223
|
+
self.begin <= other.begin && self.end >= other.end
|
224
|
+
when Enumerable
|
225
|
+
other.all? { |ip| include?(ip) }
|
226
|
+
else
|
227
|
+
false
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
#
|
232
|
+
# Calculates the size of the IP range.
|
233
|
+
#
|
234
|
+
# @return [Integer]
|
235
|
+
#
|
236
|
+
# @since 1.1.0
|
237
|
+
#
|
238
|
+
def size
|
239
|
+
(@end_uint - @begin_uint) + 1
|
240
|
+
end
|
241
|
+
|
227
242
|
#
|
228
243
|
# Converts the IP range to a String.
|
229
244
|
#
|