Skip to content

Instantly share code, notes, and snippets.

@jasonlyles
Created October 14, 2009 20:53
Show Gist options
  • Save jasonlyles/210398 to your computer and use it in GitHub Desktop.
Save jasonlyles/210398 to your computer and use it in GitHub Desktop.
#data_getter.rb
require 'server'
localhost = Server.new
#server.rb
require 'win32ole'
class Server
attr_accessor :ip_address,:route_table,:netmask,:hostname,:default_gateway,:registry_user_base_dir,:registry_sql_connect
def initialize
@ole_cnnxn = WIN32OLE.connect("winmgmts://")
magic_routes
ipconfig
get_registry
end
def magic_routes
@route_table = {}
query = "select * from Win32_IP4RouteTable"
@ole_cnnxn.ExecQuery(query).each do |route|
@route_table.merge!(:"#{route.Destination}" => {:netmask => route.Mask, :default_gateway => route.NextHop, :metric => route.Metric1})
end
end
def ipconfig
query = "select * from Win32_NetworkAdapterConfiguration where IPEnabled = True"
@ole_cnnxn.ExecQuery(query).each do |nic|
@ip_address = nic.IpAddress.to_s
@netmask = nic.IpSubnet.to_s
@default_gateway = nic.DefaultIPGateway.to_s
@hostname = nic.DNSHostName
end
end
def get_registry
obj = WIN32OLE.new('WScript.Shell')
path = "HKEY_LOCAL_MACHINE\\SOFTWARE\\@Backup\\BackupServerV2\\CurrentVersion\\Main\\"
#think something like this would be cool if I could get it to work
#reg_keys = {:registry_user_base_dir => "UserBaseDir",:registry_sql_connect => "SQLConnectString"}
#reg_keys.each do |k,v|
# self."#{k}" = obj.RegRead("#{path}#{v}")
#end
@registry_user_base_dir = obj.RegRead("#{path}UserBaseDir")
@registry_sql_connect = obj.RegRead("#{path}SQLConnectString")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment