emonti / jruby_jrmi_toys
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
dfa6808
jruby_jrmi_toys / rmiquery.rb
| dfa68087 » | emonti | 2009-02-05 | 1 | #!/usr/bin/env jruby | |
| 2 | # emonti@matasano.com - 2008 | ||||
| 3 | # | ||||
| 4 | # This script will attempt to enumerate RMI interfaces and their exposed | ||||
| 5 | # methods using JRuby. | ||||
| 6 | # | ||||
| 7 | # The script takes one argument, which is the URL for a remote RMI registry. | ||||
| 8 | # Example: | ||||
| 9 | # | ||||
| 10 | # rmiquery.rb //127.0.0.1:1099 | ||||
| 11 | # | ||||
| 12 | # Method names and prototypes are only available if RMI application stubs are | ||||
| 13 | # included. You can include them by dropping their JAR or class files into | ||||
| 14 | # the same directory that you run this script from and they will be | ||||
| 15 | # automatically loaded. | ||||
| 16 | # | ||||
| 17 | # For info on RMI: | ||||
| 18 | # | ||||
| 19 | # java.rmi.Naming @ | ||||
| 20 | # http://java.sun.com/j2se/1.5/docs/api/java/rmi/Naming.html | ||||
| 21 | # | ||||
| 22 | # java.rmi.registry.LocateRegistry @ | ||||
| 23 | # http://java.sun.com/j2se/1.5/docs/api/java/rmi/registry/LocateRegistry.html | ||||
| 24 | |||||
| 25 | include Java | ||||
| 26 | import java.rmi.Naming | ||||
| 27 | |||||
| 28 | require 'pp' | ||||
| 29 | |||||
| 30 | unless (regurl = ARGV[0]) | ||||
| 31 | STDERR.puts "need a rmiregistry url i.e. //127.0.0.1:1099" | ||||
| 32 | exit 1 | ||||
| 33 | end | ||||
| 34 | |||||
| 35 | # load all jar files in the current dir | ||||
| 36 | Dir.foreach(".") do |x| | ||||
| 37 | if x =~ /\.jar$/ | ||||
| 38 | STDERR.puts "Importing #{x}" | ||||
| 39 | require x | ||||
| 40 | end | ||||
| 41 | end | ||||
| 42 | |||||
| 43 | STDERR.puts | ||||
| 44 | registry = Naming.lookup(regurl) | ||||
| 45 | registry.list.each do |remote_name| | ||||
| 46 | puts "RMI Interface Found: #{remote_name}" | ||||
| 47 | begin | ||||
| 48 | remote = registry.lookup(remote_name) | ||||
| 49 | puts " #{remote}" | ||||
| 50 | remote.java_class.declared_instance_methods.each do |meth| | ||||
| 51 | puts " #{meth.to_s}" | ||||
| 52 | end | ||||
| 53 | rescue | ||||
| 54 | puts " **ERROR** #{$!}" | ||||
| 55 | end | ||||
| 56 | puts | ||||
| 57 | end | ||||
