함수 is port open()

(함수 is open port()에서 넘어옴)

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