<?php class generator1 { //const HOSTS = array(array(‘ubuntu‘=>‘123.57.221.66‘),array(‘pay_web‘=>‘101.201.222.104‘),array(‘video_web‘=>‘101.201.31.40‘),array(‘bg_web211‘=>‘123.56.181.211‘),array(‘quanzi‘=>‘101.201.55.37‘),array(‘bg_web231‘=>‘60.205.127.231‘),array(‘db2_master‘=>‘60.205.166.72‘),array(‘db2_slave‘=>‘60.205.166.74‘),array(‘db3_others‘=>‘59.110.11.16‘),array(‘test_web‘=>‘60.205.150.53‘),array(‘nfs1_redis2‘=>‘123.57.184.167‘),array(‘nfs1_redis1‘=>‘123.57.184.235‘),array(‘zhuanfaqi‘=>‘123.57.185.38‘),array(‘prepare_web‘=>‘59.110.8.82‘),array(‘bg_web64‘=>‘10.29.130.64‘)); //define("HOSTS",array(‘123.57.221.66‘,‘101.201.222.104‘,‘101.201.31.40‘,‘123.56.181.211‘,‘101.201.55.37‘,‘60.205.127.231‘,‘60.205.166.72‘,‘60.205.166.74‘,‘59.110.11.16‘,‘60.205.150.53‘,‘123.57.184.167‘,‘123.57.184.235‘,‘123.57.185.38‘,‘59.110.8.82‘,‘10.29.130.64‘)); const HOSTS = array(‘123.57.203.66‘,‘101.101.222.104‘,‘102.221.51.40‘,‘112.56.131.211‘,‘121.202.45.37‘,‘101.205.127.231‘,‘101.205.166.72‘,‘63.205.166.74‘,‘39.110.13.12‘,‘65.205.150.53‘,‘33.57.134.167‘,‘123.59.104.235‘,‘148.57.135.38‘,‘59.190.8.77‘,‘10.29.130.52‘); const HOSTNAMES = array(‘ubuntu‘,‘pay_web104‘,‘video_web40‘,‘bg_web211‘,‘quanzi37‘,‘bg_web231‘,‘db2_master72‘,‘db2_slave74‘,‘db3_others‘,‘test_web‘,‘nfs1_redis1‘,‘nfs2_redis2‘,‘zhuanfaqi‘,‘prepare_web‘,‘bg_web64‘); // 密码生成器函数 public function generator_pass(){ $time = time(); //$md5($string); md5 函数也可以为字符串生成一个随机的值 $string = $time . "[email protected]#$%^&"; $string1 = str_shuffle($string); //$password = chunk_split($string1,9); 会在第9个位置插入一个指定的字符串 $password = mb_substr($string1,0,12); return $password; //var_dump($string1."\n"); //var_dump($password."\n"); } // 为主机生成密码并记录日志 public function produce_pass_for_hosts(){ $new_hosts = array(); $hosts = generator1::HOSTS; $hostnames = generator1::HOSTNAMES; for($i=0;$i<count($hosts);$i++){ $new_hosts[$i][‘hostname‘] = $hostnames[$i]; $new_hosts[$i][‘host‘] = $hosts[$i]; $new_hosts[$i][‘password‘] = $this->generator_pass(); } return $new_hosts; } } $gen = new generator1(); $host_info = $gen->produce_pass_for_hosts(); var_dump($host_info); ?>
python 写习惯了,写php还是有些不习惯!!多多联系吧!乐在其中!!
时间: 2024-10-12 19:29:03