quick and dirty local portscan

Forum rules
Before you post please read how to get help
User avatar
Habitual
Level 13
Level 13
Posts: 4593
Joined: Sun Nov 21, 2010 8:31 pm
Location: Youngstown, Ohio
Contact:

quick and dirty local portscan

Postby Habitual » Wed Jul 13, 2011 3:12 pm

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

User avatar
vrkalak
Level 12
Level 12
Posts: 4430
Joined: Mon Jul 20, 2009 5:53 pm
Location: Santa Fe, NM, USA

Re: quick and dirty local portscan

Postby vrkalak » Wed Jul 13, 2011 3:17 pm

Habitual is gonna have, so much fun, playing with his new Forum/Section. :lol:
Image
:: Debian-Sid (Xfce/Fluxbox) :: LinuxMint-18 (LTS) LXDE w/Openbox ::
Registered Linux User: #497031 :: My DeviantART Page

User avatar
Habitual
Level 13
Level 13
Posts: 4593
Joined: Sun Nov 21, 2010 8:31 pm
Location: Youngstown, Ohio
Contact:

Re: quick and dirty local portscan

Postby Habitual » Wed Jul 13, 2011 3:19 pm

I better not be alone, else I'll have to pick up another language. :wink:

User avatar
xenopeek
Level 24
Level 24
Posts: 20181
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: quick and dirty local portscan

Postby xenopeek » Wed Jul 13, 2011 3:19 pm

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

User avatar
Habitual
Level 13
Level 13
Posts: 4593
Joined: Sun Nov 21, 2010 8:31 pm
Location: Youngstown, Ohio
Contact:

Re: quick and dirty local portscan

Postby Habitual » Wed Jul 13, 2011 6:34 pm

Vincent Vermeulen 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:

User avatar
samriggs
Level 6
Level 6
Posts: 1055
Joined: Sun Apr 24, 2011 6:09 pm
Location: Canada
Contact:

Re: quick and dirty local portscan

Postby samriggs » Thu Jul 14, 2011 12:07 am

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
"Windows: the worst system for the most money, Linux: the best system for free"
Registered Linux User #545430
Arch Cinnamon / Mint Cinnamon
asus X751LX and an acer and a toshiba and another asus

Spec-chum
Level 1
Level 1
Posts: 48
Joined: Tue May 31, 2011 3:22 pm

Re: quick and dirty local portscan

Postby Spec-chum » Thu Jul 14, 2011 3:41 am

+1 for java and c/c++.

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

User avatar
samriggs
Level 6
Level 6
Posts: 1055
Joined: Sun Apr 24, 2011 6:09 pm
Location: Canada
Contact:

Re: quick and dirty local portscan

Postby samriggs » Fri Jul 15, 2011 12:49 am

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
"Windows: the worst system for the most money, Linux: the best system for free"
Registered Linux User #545430
Arch Cinnamon / Mint Cinnamon
asus X751LX and an acer and a toshiba and another asus


Return to “Scripts & Bash”

Who is online

Users browsing this forum: No registered users and 1 guest