포트 스캐너는 상대방의 포트를 스캔하는 것을 말합니다. 해커들이 만들어 사용한다는 포트 스캐너입니다. 화면의 그림에서 "server name"에는 도메인 이름 또는 ipv4 나 ipv6 주소를 입력하고, 알고자 하는 서비스명 또는 "other port"에 적당한 포트를 입력하고 전송을 하면 그 결과 값이 출력됩니다. 결과적으로 파란색만 사용가능함을 표시합니다.


서버가 윈도우라면 기본적으로 php_sockets.dll 모듈이 비활성화 상태이므로 php.ini 를 수정해서 활성화해줘야 socket 함수를 사용할 수 있습니다.

 <!DOCTYPE HTML SYSTEM "about:legacy-compat">

 <form action="" method="POST">
    Server Name: <input type="text" name="servername" size="30" value="" autofocus required placeholder="ex) example.com or ip address" />
    <br />
    Service :
    <input type="checkbox" name="port[]" value="21" />ftp
    <input type="checkbox" name="port[]" value="23" />telnet
    <input type="checkbox" name="port[]" value="25" />smtp
    <input type="checkbox" name="port[]" value="80" />http
    <input type="text" name="port[]" value="" placeholder="other port" />
    <br />
    <input type="Submit" name="result" value="전 송"/>
 </form>
 

 <?php
 if(!empty($_POST['result']) && ($_SERVER['REQUEST_METHOD'] === 'POST'))
 {
    ini_set("max_execution_time", 120);

    $servername = preg_replace("/[^a-z0-9.-:]/i", "", $_POST['servername']);
    if(!empty($servername) && function_exists("socket_create"))
    {
        if(is_array($_POST['port']))
        {
            $output = array();
            $socket = @socket_create(AF_INET, SOCK_STREAM, 0);

            foreach($_POST['port'] as $p)
            {
                $num = preg_replace("/[^0-9]/", "", $p);
                if($num)
                {
                    $result = @socket_connect($socket, $servername, $p);
                    if(!$result)
                    {
                        $output[] = "<font color='red'>" . $p . "port service is not</font>\n";
                    }
                    else
                    {
                        $output[] = "<font color='blue'>" . $p . "port is the service</font>\n";
                    }
                }
            }
            @socket_close($socket);
        }        

        echo '<pre>';
        print_r($output);
    }
 }
 ?>

0 댓글