CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/scripts/meterpreter/get_local_subnets.rb
Views: 11767
1
##
2
# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
3
# If you'd like to improve this script, please try to port it as a post
4
# module instead. Thank you.
5
##
6
7
8
# Meterpreter script that display local subnets
9
# Provided by Nicob <nicob [at] nicob.net>
10
# Ripped from http://blog.metasploit.com/2006/10/meterpreter-scripts-and-msrt.html
11
12
@@exec_opts = Rex::Parser::Arguments.new(
13
"-h" => [ false, "Help menu." ]
14
)
15
def usage
16
print_line("Get a list of local subnets based on the host's routes")
17
print_line("USAGE: run get_local_subnets")
18
print_line(@@exec_opts.usage)
19
raise Rex::Script::Completed
20
end
21
22
@@exec_opts.parse(args) { |opt, idx, val|
23
case opt
24
when "-h"
25
usage
26
end
27
}
28
29
client.net.config.each_route { |route|
30
# Remove multicast and loopback interfaces
31
next if route.subnet =~ /^(224\.|127\.)/
32
next if route.subnet == '0.0.0.0'
33
next if route.netmask == '255.255.255.255'
34
print_line("Local subnet: #{route.subnet}/#{route.netmask}")
35
}
36
37