![NC 포트 스캔을 사용할 때 성공 메시지를 필터링하는 방법](https://linux55.com/image/89598/NC%20%ED%8F%AC%ED%8A%B8%20%EC%8A%A4%EC%BA%94%EC%9D%84%20%EC%82%AC%EC%9A%A9%ED%95%A0%20%EB%95%8C%20%EC%84%B1%EA%B3%B5%20%EB%A9%94%EC%8B%9C%EC%A7%80%EB%A5%BC%20%ED%95%84%ED%84%B0%EB%A7%81%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
다음 명령을 사용하여 내 컴퓨터에서 포트 스캔을 수행합니다.
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>&1
stderr
프로그램이 원인과 동일한 파일 설명자에 기록되고 있습니다 stdout
. 기본적으로 nc
을 작성하면 stderr
파이프는 가져오기만 하므로 stdout
grep은 데이터를 잃게 됩니다.
자세한 내용은 여기에서 섹션 3.5를 참조하세요.리디렉션에 관한 모든 것.