2013년 11월 26일 화요일

PHP에서 윈도우 그룹, 사용자이름 추적

자료출처: 노홍균님의 글

<?php
function netbios_name($ipaddress) {

// return value
// $names = array( $ws_name , $dc_name , $fs_name, $w2k_name, $g_name, $user_name ,$dm_name );


$nmblookup = "/usr/local/samba/bin/nmblookup" ;
$option = " -A " ;
$tempfile = "/tmp/netbios";
$command = "$nmblookup $option $ipaddress > $tempfile" ;

$command_1 = "rm -rf $tempfile" ;

system($command1);
$result = system($command);

// $s=microtime();

$fp=fopen("$tempfile", "r");

while(!feof($fp)) {

  $file_line = fgets($fp,200);
  $line_count = 0 ;

 
  if ($file_line)
   {  
     $line_count = $line_count + 1;

         if (ereg ("<00>", $file_line, $row)) {        // 웍스테이션 이름 $ws_name
            $split = explode( " ", $file_line);
                $result ="$split[0]";
        $ws_name = $result ;
                }


         if (ereg ("<1c>", $file_line, $row)) {         // DC 이름 $dc_bane
            $split = explode( " ", $file_line);
                $result ="$split[0]";
        $dc_name = $result ;
                }

    
         if (ereg ("<20>", $file_line, $row)) {         // 파일 공유서버  fs_name
            $split = explode( " ", $file_line);
                $result ="$split[0]";
        $fs_name = $result ;
                }

         if (ereg ("<1b>", $file_line, $row)) {         // W2k or Nt4.0서버  w2k_name
            $split = explode( " ", $file_line);
                $result ="$split[0]";
        $w2k_name = $result ;
                }

         if (ereg ("<1e>", $file_line, $row)) {         // group name   g_name
            $split = explode( " ", $file_line);
                $result ="$split[0]";
        $g_name = $result ;
                }

         if (ereg ("<03>", $file_line, $row)) {         // user   user_name
            $split = explode( " ", $file_line);
                $result ="$split[0]";
        $user_name = $result ;
                }

         if (ereg ("<1e>", $file_line, $row)) {         // Domain Master name   dm_name
            $split = explode( " ", $file_line);
                $result ="$split[0]";
        $dm_name = $result ;
                }

   } //if $file_line


  // 배열에 값들을 전부 넣음.

  } // end while

fclose($fp);
$names = array( $ws_name , $dc_name , $fs_name, $w2k_name, $g_name, $user_name ,$dm_name );


/*
echo ("웍스테이션 이름:  $names[0] <br>" );
echo ("DC 이름:  $names[1] <br>" );
echo ("FS 이름:  $names[2] <br>" );
echo ("W2K 이름:  $names[3] <br>" );
echo ("Group 이름:  $names[4] <br>" );
echo ("User 이름:  $names[5] <br>" );
echo ("Domain controller 이름:  $names[6] <br>" );
*/

//echo $s." > <br>".microtime();

return($names);

} // function Netbios name

?>

댓글 없음:

댓글 쓰기