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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
43번째 줄: 43번째 줄:
<syntaxhighlight lang='php'>
<syntaxhighlight lang='php'>
function is_port_open($host, $port, $timeout=2) {
function is_port_open($host, $port, $timeout=2) {
   $resyntaxhighlight = @fsockopen($host, $port, $errno, $errstr, $timeout);
   $result = @fsockopen($host, $port, $errno, $errstr, $timeout);
   if($resyntaxhighlight) return true;
   if($result) return true;
   return false;
   return false;
}
}

2022년 2월 11일 (금) 20:36 기준 최신판

1 개요[ | ]

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

2 Bash[ | ]

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

3 C#[ | ]

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

4 PHP[ | ]

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

5 같이 보기[ | ]

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