您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
公司在异地有分公司。那边要加入域。然后权限等等。。。还有就是ruby学习一下。。。
require 'net/ldap' require 'net/telnet' require 'net/http' require 'openssl' require 'base64' require 'highline/import' #隐藏输入字符 gem install highline ALG = 'DES-EDE3-CBC' KEY = "masdsdff" #你的密钥 只能8位 DES_KEY = "nseewW3E" #任意固定的值 def check_pass(auth) puts "Input Your Username" username = STDIN.gets.chomp password = ask("Input Your Password") { |q| q.echo = "*" } ldap = Net::LDAP.new ldap.host = "fw.163.net" ldap.port = 389 result = ldap.bind_as( :base => "ou=People,dc=163,dc=net", :filter => "(uid=#{username}))", :password => password ) if result auth.include?(username) ? true : false else false end end def check_network() begin Net::Telnet::new("Host" => "ad.163.net", "Port" => 80, "Telnetmode" => false) rescue puts "Can't Connect AD, Please Check Network." sleep 10 exit end end def check_hostname() if ENV["COMPUTERNAME"].downcase.scan("hw").count > 0 puts "Please Change Hostname And Restart PC" sleep 10 exit end end def usage() help=<<EOF Usage: script username password EOF puts help end def add_domain(secret) #'user1|user2||domain admin|domain admin pass|current pass' result = `netdom.exe join #{ENV["COMPUTERNAME"]} /domain:163.net /userd:#{secret[2].strip} /passwordd:#{secret[3].strip} /usero:#{ENV["USER"]} /passwordo:#{secret[4].strip}` result.scan("success").count > 0 ? true : false end def encode(str) des = OpenSSL::Cipher::Cipher.new(ALG) des.pkcs5_keyivgen(KEY, DES_KEY) des.encrypt cipher = des.update(str) cipher << des.final return Base64.encode64(cipher) #Base64编码,才能保存到数据库 end def decode(str) str = Base64.decode64(str) des = OpenSSL::Cipher::Cipher.new(ALG) des.pkcs5_keyivgen(KEY, DES_KEY) des.decrypt des.update(str) + des.final end #----------------------- check_network() #usage() 本来用参数,现在改输入 secret = decode(Net::HTTP.get(URI('http://fw.163.net/auth.dat')).chomp).split("|") if check_pass(secret) check_hostname() if add_domain(secret) puts "Add users to the local administrators group? (Y|N)" if STDIN.gets.scan(/[yY]/).count > 0 puts "Please enter a user to join the administrators group" `net localgroup administrators 163.net\\#{STDIN.gets.chomp} /add` end puts "Join a domain successfully" else puts "Join a domain fail" end sleep 10 exit else puts "1: username or password err; 2: unauthorized" sleep 10 exit end
然后用 ocra 编译为exe (ocra 直接 gem install ocra, 这个感觉比exerb、rubyscript2exe好)
同时程序需要 netdom.exe netapi32.dll
注,加密的是在网上找的。忘记哪了。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。