LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to filter the success message when using nc port scan (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-filter-the-success-message-when-using-nc-port-scan-4175583327/)

P.G.Krish 06-29-2016 07:14 AM

How to filter the success message when using nc port scan
 
I used following command for port scanning of my machine
Code:

nc -zv 192.168.1.1 1-100
but I want to filter only succeeded message from following output.Hence i used the following command
Code:

nc -zv 192.168.1.1 1-100|grep succeeded
But no improvement still it shows full output

TB0ne 06-29-2016 07:39 AM

Quote:

Originally Posted by P.G.Krish (Post 5567843)
I used following command for port scanning of my machine
Code:

nc -zv 192.168.1.1 1-100
but I want to filter only succeeded message from following output.Hence i used the following command
Code:

nc -zv 192.168.1.1 1-100|grep succeeded
But no improvement still it shows full output

Would help if you posted what, exactly, you're seeing, and what you WANT to see. If you pipe it into grep, it will show you EVERYTHING with the word "succeeded" on it, just as you asked it to. So if that's what it's doing, why are you expecting it to do anything else?

Show us what you get, and tell us what you WANT.

P.G.Krish 06-29-2016 08:38 AM

I want to filter success message which is only when the ports are open .Many ports give error message, i dont want to see that , I only see the open ports

TB0ne 06-29-2016 08:48 AM

Quote:

Originally Posted by P.G.Krish (Post 5567885)
I want to filter success message which is only when the ports are open .Many ports give error message, i dont want to see that , I only see the open ports

And AGAIN....you need to post WHAT YOU ARE SEEING and what you WANT TO SEE. Re-stating your question and providing no additional information tells us nothing. Again, we can't guess.

Post a sample of the command output, and then post what you WANT to see.

P.G.Krish 06-29-2016 08:55 AM

It the output .I want to filter the particular line which has succeeded
 
Quote:

Originally Posted by TB0ne (Post 5567890)
And AGAIN....you need to post WHAT YOU ARE SEEING and what you WANT TO SEE. Re-stating your question and providing no additional information tells us nothing. Again, we can't guess.

Post a sample of the command output, and then post what you WANT to see.

Code:

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
nc: connect to 192.168.1.1 port 10 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 11 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 12 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 13 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 14 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 15 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 16 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 17 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 18 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 19 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 20 (tcp) failed: Connection refused
Connection to 192.168.1.1 21 port [tcp/ftp] succeeded!
nc: connect to 192.168.1.1 port 22 (tcp) failed: Connection refused


grail 06-29-2016 08:58 AM

So, assuming you are saying that even with the grep you would get all of the above output and not just the 'succeeded' line, it could be that nc output to stderr and not stdout, so try a redirect
and see if that improves your results?

TB0ne 06-29-2016 09:09 AM

Quote:

Originally Posted by P.G.Krish (Post 5567894)
Code:

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
nc: connect to 192.168.1.1 port 10 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 11 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 12 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 13 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 14 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 15 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 16 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 17 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 18 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 19 (tcp) failed: Connection refused
nc: connect to 192.168.1.1 port 20 (tcp) failed: Connection refused
Connection to 192.168.1.1 21 port [tcp/ftp] succeeded!
nc: connect to 192.168.1.1 port 22 (tcp) failed: Connection refused


Great...so you were asked for:
  • What you SEE
  • What you WANT to see
...and posted that, and don't post what you WANT to see. Again, you're not posting what you're after, but based on your question, did you read the man pages on the nc command? nc outputs logs to stderr, so you need to redirect before grep'ing:
Code:

nc -zv <address> 1-100 2>&1 | grep succeeded
When people ask you to clarify things, and you don't, it's frustrating, and makes people NOT want to help you.

P.G.Krish 06-29-2016 09:27 AM

Quote:

Originally Posted by TB0ne (Post 5567905)
Great...so you were asked for:
  • What you SEE
  • What you WANT to see
...and posted that, and don't post what you WANT to see. Again, you're not posting what you're after, but based on your question, did you read the man pages on the nc command? nc outputs logs to stderr, so you need to redirect before grep'ing:
Code:

nc -zv <address> 1-100 2>&1 | grep succeeded
When people ask you to clarify things, and you don't, it's frustrating, and makes people NOT want to help you.

Thanks TB0ne , i will correct my mistakes.


All times are GMT -5. The time now is 03:21 PM.