port 22 opened port 80 opened port 631 opened port 3306 opened port 3690 opened port 6665 opened port 6666 opened port 6667 opened port 6668 opened port 6669 opened port 7048 opened port 8079 opened port 8280 opened port 8885 opened port 8888 opened port 9127 opened port 23791 opened port 23943 opened port 33556 opened port 34482 opened port 39447 opened port 48030 opened port 51687 opened real 4m33.201s user 1m16.657s sys 2m42.194s
While `lsof` will work, why not use the tool designed explicitly for this job? (If not run as root, you will only see the names of PID you own) Show Sample Output
Alternative of OJM snippet : This one show the IP too, where ports bind. It's very important, because if there's only 127.0.0.1 instead of 0.0.0.0, connections from internet are rejected.
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.
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.
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
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:
nc -w2 -z host.tld && echo open
To test all the ports, the good tool is nmap. But that's a good start to re-code a nmap fork from sctratch ;) Last point, I edited your snippet shorter :time { while (( c < 65535 )); do nc -w2 -z localhost $((++c)) && echo port $c opened ; done; }
time { for ((i=1;i<65535;i++));do nc -zw2 localhost $i && echo port $i opened;done;}
time { for i in {1..65534}; do nc -zw2 localhost $i && echo "$i open"; done; }