Port scan a range of hosts with Netcat.

for i in {21..29}; do nc -v -n -z -w 1 192.168.0.$i 443; done
Simple one-liner for scanning a range of hosts, you can also scan a range of ports with Netcat by ex.: nc -v -n -z -w 1 192.168.0.1 21-443 Useful when Nmap is not available:) Range declaration like X..X "for i in {21..29}" is only works with bash 3.0+
Sample Output
(UNKNOWN) [192.168.0.21] 443 (?) : Connection refused
(UNKNOWN) [192.168.0.22] 443 (?) open
(UNKNOWN) [192.168.0.23] 443 (?) : Connection refused
(UNKNOWN) [192.168.0.24] 443 (?) open
....
...

9
By: rez0r
2009-09-25 03:31:29

What Others Think

For other Bourne family shells try for i in $(seq 21 29); do nc -v -n -z -w 1 192.168.0.$i 443; done instead.
penpen · 473 weeks and 1 day ago
On some distributions the command name is 'netcat', not 'nc', so try both.
hfs · 413 weeks and 2 days ago
one liner for powershell on windows. for ($i=1; $i++){if ($i -lt 255){.\nc.exe -v -n -z -w 1 192.168.0.$i 80;}}
tasdawg · 46 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: