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

 
(사용자 2명의 중간 판 10개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
[[category: network]]
;is_port_open
;is_port_open
;is_port_listen
;is_port_listen
6번째 줄: 8번째 줄:


==Bash==
==Bash==
<source lang='bash'>
[[category: Bash]]
<syntaxhighlight lang='bash'>
IP=8.8.8.8
IP=8.8.8.8
PORT=53
PORT=53
TIMEOUT=3
TIMEOUT=2
IS_OPEN_PORT=`nc -z -w$TIMEOUT $IP $PORT`
IS_PORT_OPEN=`nc -z -w$TIMEOUT $IP $PORT`
if [ "$IS_OPEN_PORT" = "" ]
if [ "$IS_PORT_OPEN" = "" ]
then
then
IS_OPEN_PORT=false
IS_PORT_OPEN=false
else
else
IS_OPEN_PORT=true
IS_PORT_OPEN=true
fi
fi
echo $IS_OPEN_PORT
echo $IS_PORT_OPEN
# true
# true
</source>
</syntaxhighlight>


==C#==
==C#==
<source lang='csharp'>
[[category: csharp]]
<syntaxhighlight lang='csharp'>
private bool isPortOpen(string host, int port) {
private bool isPortOpen(string host, int port) {
   try {
   try {
33번째 줄: 37번째 줄:
   return true;
   return true;
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
<source lang='php'>
[[category: PHP]]
function is_port_open($host, $port) {
<syntaxhighlight lang='php'>
  $timeout = 3;
function is_port_open($host, $port, $timeout=2) {
   $resource = @fsockopen($host, $port, $errno, $errstr, $timeout);
   $result = @fsockopen($host, $port, $errno, $errstr, $timeout);
   if($resource) return true;
   if($result) return true;
   return false;
   return false;
}
}
</source>
</syntaxhighlight>


==See also==
==같이 보기==
*[[ping]]
*[[is_ping()]]
*[[리눅스 로컬서버 열린 포트 확인]]
*[[리눅스 로컬서버 열린 포트 확인]]
[[category: network]]
[[category: Bash]]
[[category: csharp]]
[[category: PHP]]

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 }}