Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
TCP: Fast check for open port
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 672
Location: Belgium

PostPosted: Fri Jan 23, 2009 11:31 pm    Post subject: TCP: Fast check for open port Reply with quote

I need a more or less quick way to find out if a TCP port on a system on the LAN is open, from a script. I was thinking in the direction of return values of bash's /dev/tcp/<ip>/<port>, but the timeout is pretty high. I succeeded in decreasing it by fiddling with /proc/sys/net/ipv4/tcp_syn_retries. But I guess this will affect every TCP connection on my box.

Any other nice way to do this? (maybe without fiddling with the "global" kernel parameters?)
Back to top
View user's profile Send private message
vaguy02
Guru
Guru


Joined: 25 Feb 2005
Posts: 424
Location: Hopefully in one place

PostPosted: Fri Jan 23, 2009 11:37 pm    Post subject: Reply with quote

I'd use nmap, but that's just me. I bet there are 100001 programs out there to do it.
_________________
Linux Registered User #458185

Intel Quad-Core w/ 4gigs Ram w/ 8800 GTX - Windows 7 RC
2x (Intel Dual-Core w/ 2gigs Ram - Gentoo)
Mac G5 Dual-Core w/ 2gigs Ram - OS 10.5
Back to top
View user's profile Send private message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 672
Location: Belgium

PostPosted: Fri Jan 23, 2009 11:41 pm    Post subject: Reply with quote

It would be nice if it ran from a Gentoo minimal LiveCD, so bash was my first idea. And it works, but the question is about the TCP properties...
Back to top
View user's profile Send private message
keyson
l33t
l33t


Joined: 10 Jun 2003
Posts: 830
Location: Sweden

PostPosted: Fri Jan 23, 2009 11:53 pm    Post subject: Reply with quote

Hi,

You have netcat (nc) on the liveCD. You can use that to check for open ports.
ref:
http://www.adamsinfo.com/netcat-tutorial-for-linux-windows-howto-nc/
Back to top
View user's profile Send private message
OneOfOne
Guru
Guru


Joined: 28 May 2003
Posts: 368

PostPosted: Sat Jan 24, 2009 1:06 am    Post subject: Reply with quote

Perl ftw
perl -m'IO::Socket' -e '$s = new IO::Socket::INET(PeerAddr => $ARGV[0],PeerPort => $ARGV[1], Proto => "tcp", Timeout => 3); print $s "hi server\n"; print(<$s>); print("\n");' host-name port
Back to top
View user's profile Send private message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2719
Location: here, there or in transit

PostPosted: Sat Jan 24, 2009 2:16 am    Post subject: Reply with quote

OneOfOne wrote:
Perl ftw
I wouldn't call that a win over the equivalent:
Code:
netcat -zw 3 <host-name> <port> && echo alive || echo refused
...but maybe that's just me. :wink:

Addressing the question from the OP: AFAIK you're right, pure bash can't do this unless you fiddle with global TCP settings, which is kind of a Bad Thing.
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.


Last edited by timeBandit on Sat Jan 24, 2009 2:18 am; edited 1 time in total
Back to top
View user's profile Send private message
Kobboi
l33t
l33t


Joined: 29 Jul 2005
Posts: 672
Location: Belgium

PostPosted: Sat Jan 24, 2009 2:18 am    Post subject: Reply with quote

But netcat is not on the minimal install CD :)
Back to top
View user's profile Send private message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2719
Location: here, there or in transit

PostPosted: Sat Jan 24, 2009 2:20 am    Post subject: Reply with quote

Kobboi wrote:
But netcat is not on the minimal install CD :)
Sorry, I misread keyson's reply, or maybe yours, and missed the "minimal" part. :oops: Perl FTW indeed. :)
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum