ÀÌ ÈÀÏÀ» ¾òÀ¸·Á¸é À¥ºê¶ó¿ìÀú¿¡¼ network.lib¶õ À̸§ÀÇ 'ÅؽºÆ®(Text)' ÇüÅ·ΠÀúÀåÇ϶ó.
PHP: network adminstrator's best friend from http://www.phpWizard.net
À¥°³¹ßÀڷμ ¾Æ¸¶ ping, whois, nslookup µîµîÀÇ À¯¿ëÇÑ ÅøÀ» »ç¿ëÇÒ°ÍÀÌ´Ù. ±×·¯³ª °í°´ÀÇ »ç¹«½Ç¿¡¼ ±× ÅøÁß Çϳª¸¦ »ç¿ëÇؾߵǴµ¥ telnetÀ» »ç¿ëÇÒ¼ö ¾ø´Ù¸é ¾î¶»°ÔÇÒ°ÍÀΰ¡? PHP ¸Å´º¾óÀÇ '³×Æ®¿öÅ©'¿¡¼ functionÀ» ã¾Æº¸´Â °ÍÀÌ ´ë¾ÈÀÌ´Ù.
¼ÒÄÏ ÀÛµ¿ :
°¡Àå Áß¿äÇÑ ÇÔ¼ö´Â fsockopen()ÀÌ´Ù. ÀÌÇÔ¼ö¸¦ »ç¿ëÇÏ¸é ¼¹öÀÇ ¿·ÁÁø ¾î¶² Æ÷Æ®·Îµµ Á¢¼ÓÇÒ¼ö ÀÖ°í ¼ÒÄÏÀÇ ¿¬°áÀ» ¼³Á¤ÇÒ¼ö ÀÖ´Ù. ÇÔ¼öÀÇ ¹®¹ýÀº ´ÙÀ½°ú °°´Ù :
int fsockopen(string hostname, int port, int [errno], string [errstr]);
±×·¡¼, À¥¼¹ö¿¡ ¿¬°áÇϱâ À§ÇØ ÀÌÇÔ¼ö¸¦ »ç¿ëÇÏ°í Çì´õ¸¦ ÇÁ¸°Æ®Ç϶ó :
function get_headers($host, $path = "/") { $fp = fsockopen ("$host", 80, &$errnr, &$errstr) or die("$errno: $errstr"); fputs($fp,"GET $path HTTP/1.0\n\n"); while (!$end) { $line = fgets($fp, 2048); if (trim($line) == "") $end = true; else echo $line; } fclose($fp); }
Áö½Ã:
ÀϹÝÀûÀ¸·Î ´Ù¸¥ Æ÷Æ®·Î ¿¬°á ÇÒ¼ö ÀÖ´Ù. PHP·Î ÀÛÀº ÇΰŠŬ¶óÀ̾ðÆ®¸¦ ¸¸µç°ÍÀº ½¬°Ô ÇÒ¼ö ÀÖ´Ù. ÇΰŠµ¥¸ó¿¡ Äõ¸®(Áú¹®)Çϱâ À§ÇØ ¾Æ·¡¿¡ ÀÖ´Â ¿¹Á¦¸¦ ¼öÁ¤Ç϶ó.
function finger ($host, $user) { $fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: $errstr"); fputs($fp, "$user\n"); while (!feof($fp)) echo fgets($fp, 128); fclose($fp); }
Whois: ÈÄÀ̽º(whois) ¼¹ö¿¡ Áú¹®Çϴ°͵µ °°Àº °³³äÀÌ´Ù:
// domain is like "phpwizard.net" function whois($domain, $server="whois.internic.net") { $fp = fsockopen ($server, 43, &$errnr, &$errstr) or die("$errno: $errstr"); fputs($fp, "$domain\n"); while (!feof($fp)) echo fgets($fp, 2048); fclose($fp); }
ºí·°Å·, ³Íºí·ÏÅ· Á¦¾î : ±×·¯³ª ÀÌÇÔ¼ö¸¦ »ç¿ëÇϴµ¥ ¹®Á¦°¡ ÀÖ´Ù. ´ÙÀ½°ú °°À»¶§¸¸ ÀßÀÛµ¿ÇÑ´Ù.
$fp = fsockopen($host, 79, &$errno, &$errstr) or die("$errno: [ ] $errstr"); set_socket_blocking($fp, 0); fputs($fp, "$user\n"); $stop = time() + $timeout; while (!feof($fp) && time() < $stop ) echo fgets($fp, 128); fclose($fp);