NC 포트 스캔을 사용할 때 성공 메시지를 필터링하는 방법

NC 포트 스캔을 사용할 때 성공 메시지를 필터링하는 방법

다음 명령을 사용하여 내 컴퓨터에서 포트 스캔을 수행합니다.

nc -zv 192.168.1.1 1-100

하지만 다음 출력에서는 성공한 메시지만 필터링하고 싶습니다. 그래서 다음 명령을 사용했습니다.

nc -zv 192.168.1.1 1-100|grep succeeded

하지만 작동하지 않았고 여전히 전체 출력이 표시됩니다.

nc: connect to 192.168.1.1 port 1 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 2 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 3 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 4 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 5 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 6 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 7 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 8 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 9 (tcp) failed: Connection refused

답변1

명령을 다음으로 변경합니다.

nc -zv 192.168.1.1 1-100 2>&1 | grep succeeded

2>&1stderr프로그램이 원인과 동일한 파일 설명자에 기록되고 있습니다 stdout. 기본적으로 nc을 작성하면 stderr파이프는 가져오기만 하므로 stdoutgrep은 데이터를 잃게 됩니다.

자세한 내용은 여기에서 섹션 3.5를 참조하세요.리디렉션에 관한 모든 것.

관련 정보