View previous topic :: View next topic |
Author |
Message |
Kobboi l33t
Joined: 29 Jul 2005 Posts: 672 Location: Belgium
|
Posted: Fri Jan 23, 2009 11:31 pm Post subject: TCP: Fast check for open port |
|
|
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 |
|
|
vaguy02 Guru
Joined: 25 Feb 2005 Posts: 424 Location: Hopefully in one place
|
Posted: Fri Jan 23, 2009 11:37 pm Post subject: |
|
|
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 |
|
|
Kobboi l33t
Joined: 29 Jul 2005 Posts: 672 Location: Belgium
|
Posted: Fri Jan 23, 2009 11:41 pm Post subject: |
|
|
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 |
|
|
keyson l33t
Joined: 10 Jun 2003 Posts: 830 Location: Sweden
|
|
Back to top |
|
|
OneOfOne Guru
Joined: 28 May 2003 Posts: 368
|
Posted: Sat Jan 24, 2009 1:06 am Post subject: |
|
|
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 |
|
|
timeBandit Bodhisattva
Joined: 31 Dec 2004 Posts: 2719 Location: here, there or in transit
|
Posted: Sat Jan 24, 2009 2:16 am Post subject: |
|
|
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.
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 |
|
|
Kobboi l33t
Joined: 29 Jul 2005 Posts: 672 Location: Belgium
|
Posted: Sat Jan 24, 2009 2:18 am Post subject: |
|
|
But netcat is not on the minimal install CD |
|
Back to top |
|
|
timeBandit Bodhisattva
Joined: 31 Dec 2004 Posts: 2719 Location: here, there or in transit
|
Posted: Sat Jan 24, 2009 2:20 am Post subject: |
|
|
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. 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 |
|
|
|