mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-11-12 11:52:01 +01:00
add cidr parsing for ipv6
git-svn-id: file:///home/svn/framework3/trunk@7707 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
parent
1e6b6b3d62
commit
a96a23f95c
@ -35,13 +35,7 @@ class RangeWalker
|
||||
return nil if not parseme
|
||||
ranges = []
|
||||
parseme.split(' ').each { |arg|
|
||||
if arg.include?(":")
|
||||
# Then it's IPv6
|
||||
# Can't really do much with IPv6 right now, just return it and
|
||||
# hope for the best
|
||||
addr = Rex::Socket.addr_atoi(arg)
|
||||
ranges.push [addr, addr, true]
|
||||
elsif arg.include?("/")
|
||||
if arg.include?("/")
|
||||
# Then it's CIDR notation and needs special case
|
||||
if arg =~ /[,-]/
|
||||
# Improper CIDR notation (can't mix with 1,3 or 1-3 style IP ranges)
|
||||
@ -53,6 +47,12 @@ class RangeWalker
|
||||
else
|
||||
return false
|
||||
end
|
||||
elsif arg.include?(":")
|
||||
# Then it's IPv6
|
||||
# Can't really do much with IPv6 right now, just return it and
|
||||
# hope for the best
|
||||
addr = Rex::Socket.addr_atoi(arg)
|
||||
ranges.push [addr, addr, true]
|
||||
elsif arg =~ /[^-0-9,.*]/
|
||||
# Then it's a domain name and we should send it on to addr_atoi
|
||||
# unmolested to force a DNS lookup.
|
||||
@ -141,6 +141,7 @@ class RangeWalker
|
||||
range = Range.new
|
||||
range.start = Rex::Socket.addr_atoi(start)
|
||||
range.stop = Rex::Socket.addr_atoi(stop)
|
||||
range.ipv6 = (arg.include?(":"))
|
||||
|
||||
return [range]
|
||||
end
|
||||
@ -283,8 +284,10 @@ end
|
||||
class Range < Array
|
||||
def start; self[0]; end
|
||||
def stop; self[1]; end
|
||||
def ipv6; self[2]; end
|
||||
def start=(val); self[0] = val; end
|
||||
def stop=(val); self[1] = val; end
|
||||
def ipv6=(val); self[2] = val; end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -95,6 +95,25 @@ describe Rex::Socket::RangeWalker do
|
||||
walker.length.should == 512
|
||||
end
|
||||
|
||||
it "should handle ipv6 cidr" do
|
||||
walker = Rex::Socket::RangeWalker.new("::1/127")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2
|
||||
walker = Rex::Socket::RangeWalker.new("::1/122")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2 ** 6
|
||||
walker = Rex::Socket::RangeWalker.new("::1/116")
|
||||
walker.should be_valid
|
||||
walker.length.should == 2 ** 12
|
||||
end
|
||||
|
||||
#it "should handle ipv6 ranges" do
|
||||
# pending("Need to define how this should be handled")
|
||||
# walker = Rex::Socket::RangeWalker.new("::1-::1:1")
|
||||
# walker.should be_valid
|
||||
# walker.length.should == 2 ** 16
|
||||
#end
|
||||
|
||||
it "should yield all ips" do
|
||||
walker = Rex::Socket::RangeWalker.new("10.1.1.1,2,3")
|
||||
got = []
|
||||
|
Loading…
Reference in New Issue
Block a user