Page 1 of 1

quick and dirty local portscan

Posted: Wed Jul 13, 2011 3:12 pm
by Habitual

Code: Select all

for i in `seq 1024` ; do (echo >/dev/tcp/localhost/$i) &>/dev/null && echo "TCP port $i open" || echo "TCP port $i close"; done | grep open
TCP port 22 open
TCP port 25 open
TCP port 111 open
TCP port 199 open
TCP port 631 open

Re: quick and dirty local portscan

Posted: Wed Jul 13, 2011 3:17 pm
by vrkalak
Habitual is gonna have, so much fun, playing with his new Forum/Section. :lol:

Re: quick and dirty local portscan

Posted: Wed Jul 13, 2011 3:19 pm
by Habitual
I better not be alone, else I'll have to pick up another language. :wink:

Re: quick and dirty local portscan

Posted: Wed Jul 13, 2011 3:19 pm
by xenopeek
Nice example of BASH wizardry :) BTW you don't need the grep statement in that command:

Code: Select all

for i in `seq 1024` ; do (echo >/dev/tcp/localhost/$i) &>/dev/null && echo "TCP port $i open"; done
And I do prefer one of these 3 alternatives, though you need sudo for these iirc:

Code: Select all

sudo lsof -i | grep LISTEN
sudo netstat -lptu | grep LISTEN
sudo nmap localhost | grep open

Re: quick and dirty local portscan

Posted: Wed Jul 13, 2011 6:34 pm
by Habitual
xenopeek wrote:&& echo "TCP port $i open" || echo "TCP port $i close";[/code]
I think that's why I liked this snippet, it doesn't need root|sudo privs to run.
I added the "| grep open". A whole screen full of "TCP port nn close" is a haven for missing the Open that may be buried in it.

Anyhoos, I was amazed at the inbuilt logic operator (&& echo "TCP port $i open" || echo "TCP port $i close"). It just shows how flexible Bash really is.

Add "telnet localhost nn" to the list of yours. :wink:

Re: quick and dirty local portscan

Posted: Thu Jul 14, 2011 12:07 am
by samriggs
Habitual wrote:I better not be alone, else I'll have to pick up another language. :wink:
If your talking programming languages pick up java and help me out :lol:
Been going through java jeffs book on learning java for android, eventaully to make aps obviously, then onto software for linux after that either in python, C or C++ haven't fooled around with C or C++ in years, pretty much forgot it all.
But now this bash got my interest peeked already tried a sh file to see how it goes, kinda cool 8) might enjoy this.
Sam

Re: quick and dirty local portscan

Posted: Thu Jul 14, 2011 3:41 am
by Spec-chum
+1 for java and c/c++.

I could even help people learn x86 asm if they're feeling adventurous :D

Re: quick and dirty local portscan

Posted: Fri Jul 15, 2011 12:49 am
by samriggs
Spec-chum wrote:+1 for java and c/c++.

I could even help people learn x86 asm if they're feeling adventurous :D
:D I was joking (although I do have one question for a android java issue I am having but this isn't the place for that) but hey this might not be a bad idea for a forum one section for java one for C one for C++ one for x86 one dedicated for making linux software only etc, sure there is a few hundred out there already just haven't looked into them all :shock:
They do go beyond what this forum is about though. Maybe I should start one up for these ones, don't know much of anything about them all but hey might not be a bad idea and phpbb is easy to set up.
Sam