[SOLVED] How to filter the success message when using nc port scan
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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.
It the output .I want to filter the particular line which has succeeded
Quote:
Originally Posted by TB0ne
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
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?
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.
...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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.