42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/network_scanner.rb', line 42
def get_interface_ips(interface)
ifconfig = `ifconfig`.split("\n\n").index_by{|x| x[/\w+/,0]}
inet = ifconfig[interface][/inet addr:([^\s]*)/, 1].split('.')
broadcast = ifconfig[interface][/Bcast:([^\s]*)/, 1].split('.')
mask = ifconfig[interface][/Mask:([^\s]*)/, 1].split('.')
start_first = inet[0].to_i & mask[0].to_i
start_second = inet[1].to_i & mask[1].to_i
start_third = inet[2].to_i & mask[2].to_i
start_fourth = inet[3].to_i & mask[3].to_i
first_range = start_first..broadcast[0].to_i
second_range = start_second..broadcast[1].to_i
third_range = start_third..broadcast[2].to_i
fourth_range = start_fourth..broadcast[3].to_i
@ips_to_check = []
first_range.each do |first|
second_range.each do |second|
third_range.each do |third|
fourth_range.each do |fourth|
@ips_to_check << "#{first}.#{second}.#{third}.#{fourth}"
end
end
end
end
puts "Checking ips in (#{first_range}).(#{second_range}).(#{third_range}).(#{fourth_range})"
return @ips_to_check
end
|