함수 is port open()

Jmnote (토론 | 기여)님의 2013년 12월 3일 (화) 15:46 판 (새 문서: ;is_port_open ;is_port_listen *test set :8.8.8.8, 21 → false :8.8.8.8, 53 → true ==Bash== <source lang='bash'> IP=8.8.8.8 PORT=53 TIMEOUT=3 IS_OPEN_PORT=`nc -z -w$TIMEOUT $IP $PO...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
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=3
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 = 3;
  $resource = @fsockopen($host, $port, $errno, $errstr, $timeout);
  if($resource)	return true;
  return false;
}
function is_port_open(string $host, int port) {
  $resource = @fsockopen($host, $port);
  if($resource)	return true;
  return false;
}

4 See also

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