"함수 is port open()"의 두 판 사이의 차이

잔글 (Jmnote 사용자가 Is open port 문서를 함수 Is open port() 문서로 옮겼습니다)
(차이 없음)

2015년 4월 1일 (수) 21:09 판

is_port_open
is_port_listen
  • test set
8.8.8.8, 21 → false
8.8.8.8, 53 → true

1 Bash

IP=8.8.8.8
PORT=53
TIMEOUT=2
IS_OPEN_PORT=`nc -z -w$TIMEOUT $IP $PORT`
if [ "$IS_OPEN_PORT" = "" ]
then
	IS_OPEN_PORT=false
else
	IS_OPEN_PORT=true
fi
echo $IS_OPEN_PORT
# true

2 C#

private bool isPortOpen(string host, int port) {
   try {
       TcpClient tc = new TcpClient();
       tc.Connect(host, port);
   }
   catch {
       return false;
   }
   return true;
}

3 PHP

function is_port_open($host, $port, $timeout=2) {
  $resource = @fsockopen($host, $port, $errno, $errstr, $timeout);
  if($resource)	return true;
  return false;
}

4 See also

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}