quick and dirty local portscan

Forum rules
Before you post please read how to get help

quick and dirty local portscan

Postby Habitual on 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
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2274
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Linux Mint is funded by ads and donations.
 

Re: quick and dirty local portscan

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

Habitual is gonna have, so much fun, playing with his new Forum/Section. :lol:
Image
:: Mint-Debian-Edition (Fluxbox) :: Debian-Sid (Xfce) ::
Registered Linux User: #497031 :: DeviantART Page
User avatar
vrkalak
Level 10
Level 10
 
Posts: 3471
Joined: Mon Jul 20, 2009 5:53 pm
Location: Santa Fe, NM, USA

Re: quick and dirty local portscan

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

I better not be alone, else I'll have to pick up another language. :wink:
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2274
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Re: quick and dirty local portscan

Postby xenopeek on 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
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15437
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: quick and dirty local portscan

Postby Habitual on 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:
What's a landing but a take off in reverse?
User avatar
Habitual
Level 8
Level 8
 
Posts: 2274
Joined: Sun Nov 21, 2010 8:31 pm
Location: LM17Q-Xfce

Re: quick and dirty local portscan

Postby samriggs on 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
SolydK
User avatar
samriggs
Level 5
Level 5
 
Posts: 843
Joined: Sun Apr 24, 2011 6:09 pm
Location: Canada

Re: quick and dirty local portscan

Postby Spec-chum on 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
Spec-chum
Level 1
Level 1
 
Posts: 48
Joined: Tue May 31, 2011 3:22 pm

Re: quick and dirty local portscan

Postby samriggs on 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
SolydK
User avatar
samriggs
Level 5
Level 5
 
Posts: 843
Joined: Sun Apr 24, 2011 6:09 pm
Location: Canada

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest