quick and dirty local portscan

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Habitual

quick and dirty local portscan

Post 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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
vrkalak

Re: quick and dirty local portscan

Post by vrkalak »

Habitual is gonna have, so much fun, playing with his new Forum/Section. :lol:
Habitual

Re: quick and dirty local portscan

Post by Habitual »

I better not be alone, else I'll have to pick up another language. :wink:
User avatar
xenopeek
Level 25
Level 25
Posts: 29590
Joined: Wed Jul 06, 2011 3:58 am

Re: quick and dirty local portscan

Post 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
Image
Habitual

Re: quick and dirty local portscan

Post 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:
samriggs

Re: quick and dirty local portscan

Post 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
Spec-chum

Re: quick and dirty local portscan

Post by Spec-chum »

+1 for java and c/c++.

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

Re: quick and dirty local portscan

Post 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
Locked

Return to “Scripts & Bash”