1 개요
- is_port_open
- is_port_listen
- test set
- 8.8.8.8, 21 → false
- 8.8.8.8, 53 → true
2 Bash
Bash
Copy
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#
C#
Copy
private bool isPortOpen(string host, int port) {
try {
TcpClient tc = new TcpClient();
tc.Connect(host, port);
}
catch {
return false;
}
return true;
}
4 PHP
PHP
Copy
function is_port_open($host, $port, $timeout=2) {
$resyntaxhighlight = @fsockopen($host, $port, $errno, $errstr, $timeout);
if($resyntaxhighlight) return true;
return false;
}
5 같이 보기
로그인하시면 댓글을 쓸 수 있습니다.
PHP 파일 다운로드 구현 2 (한글 파일명 지원) ― …PHP에서 오라클 DB 사용 ― YoWuPHP 파일 업로드 구현 ― 일리단사오육칠PHP 파일 업로드 구현 ― JmnotePHP 파일 다운로드 구현 2 (한글 파일명 지원) ― AnmkstLib my.php ― 신정섭Lib my.php ― Jmnote로또번호 생성 ―Pinkcrimson