LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-30-2004, 05:14 AM   #1
overbored
Member
 
Registered: Jun 2003
Posts: 58

Rep: Reputation: 15
netcat question


hi all, i'd like to use netcat in a script to send some text via sockets, but i don't know how to have it close the connection once it has finished sending all the text. usually when i use netcat i just hit ctrl-c, but i won't be there to do that while the script is running.

i was told about a -q option on some irc channels. i downloaded and installed @stake's nc 1.10 via yum (on a fedora box) but that didn't have -q. i then built gnu netcat 0.7.1 from their site and that didn't have -q either. however on my debian and gentoo boxes i have -q (got pkgs via apt and emerge, respectively)...but the system i need to run it on is the fedora box. (i also tried downloading & building the tbz from @stake's/securityfocus' site but that failed miserably.)

i've also looked into netpipes but that seems to be entirely different from what i want (the message sender is actually the server).

thanks in advance for any help.
 
Old 10-30-2004, 06:33 AM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Code:
nc -l -p 7421
and
Code:
echo 'foo' | nc -q0 othermachine 7421
 
Old 10-30-2004, 12:36 PM   #3
overbored
Member
 
Registered: Jun 2003
Posts: 58

Original Poster
Rep: Reputation: 15
the server is NOT netcat. and i already said there's no -q.
 
Old 10-30-2004, 01:12 PM   #4
cetialphav
Member
 
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88

Rep: Reputation: 16
I don't understand the problem you are having. netcat will close the connection down automatically when it detects EOF on its stdin. So when there is nothing else to send, it shuts down automatically. When using this interactively, you can cause this by sending Ctrl-D.
 
Old 10-30-2004, 01:27 PM   #5
overbored
Member
 
Registered: Jun 2003
Posts: 58

Original Poster
Rep: Reputation: 15
neither GNU netcat nor @stake netcat closes the connection on eof on any box i've tried it on. and in all the time i've used netcat i've never ever seen that.
 
Old 10-30-2004, 01:43 PM   #6
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Oh, sorry I wasn't reading very carefully..

If your netcat doesn't have -q -option, go a head and build a better one.
eg. from the sources of debian netcat.
 
Old 10-30-2004, 01:45 PM   #7
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Oh... you already did that, too.

Why the building from debian sources failed?
 
Old 10-30-2004, 02:03 PM   #8
overbored
Member
 
Registered: Jun 2003
Posts: 58

Original Poster
Rep: Reputation: 15
as i mentioned... i need to run it on is a fedora box.
 
Old 10-30-2004, 02:22 PM   #9
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Yes you did. (this time I readed the whole message (hopefully)).

What happened when you tried to build debian netcat either
-in debian, but linking it statically
or
-directly in fedora

Quick howto on building from debian sources:
Code:
apt-get install build-essential fakeroot
apt-get source foo
apt-get build-dep foo
cd foo_123.4-5
dpkg-buildpackage -rfakeroot
Quick howto on doing the same on non-debian box:
1. Surf into http://packages.debian.org/foo
2. Download the tar.gz and .diff.gz (maybe the dsc file too, for own reading).
3. Check the list of build-dependencies (none in this case).
4. Unpack and apply the debian patchset
Code:
tar xvfz foo_123.4.orig.tar.gz
zcat foo_123.4-5.diff.gz | patch -p0
5. If the package has patches split in parts (using dpatch), you have to apply them manually too.
Code:
cd foo_123.4.orig
chmod +x debian/patches/*
for i in `cat debian/patches/00list`; do debian/patches/$i.dpatch -patch ; done
touch patch-stamp
6. Compile the bastard.
Code:
chmod +x debian/rules
debian/rules build
 
Old 10-30-2004, 02:31 PM   #10
cetialphav
Member
 
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88

Rep: Reputation: 16
There must be a disconnect here. I don't know why you think the connection is not closed. I'm running the netcat that comes with Fedora Core 2.

Code:
[cetialphav@perl cetialphav]$ echo "hello" | /usr/bin/nc localhost 23
ÿý?ÿý ÿý#ÿý'[cetialphav@perl cetialphav]$
Netcat opens a TCP connection to port 23, sends "hello", sees the EOF on stdin and closes the connection and exits. Is this not what you are asking for?
 
Old 10-30-2004, 02:35 PM   #11
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
Also building in debian sources can also be done in one command:
Code:
apt-src install -b foo
And to get the thing build static binaries,
patch the debian/rules before running dpkg-buildpackage.

Here's the patch:
Code:
diff -rub netcat-1.10/debian/rules new/netcat-1.10/debian/rules
--- netcat-1.10/debian/rules    2004-10-30 22:27:35.000000000 +0300
+++ new/netcat-1.10/debian/rules        2004-10-30 22:32:19.000000000 +0300
@@ -22,7 +22,7 @@
 build-stamp: patch-stamp
        dh_testdir
        $(MAKE) linux \
-           CFLAGS='$(DEB_CFLAGS)' STATIC='' \
+           CFLAGS='$(DEB_CFLAGS)' STATIC='-static' \
            DFLAGS='-DLINUX -DTELNET -DGAPING_SECURITY_HOLE'
        touch build-stamp
 
Old 10-30-2004, 02:35 PM   #12
overbored
Member
 
Registered: Jun 2003
Posts: 58

Original Poster
Rep: Reputation: 15
cetialphav, you're wrong because the connection is closed *from the server side.* just because your netcat process ended doesn't mean that the client was the one who closed the connection. if you don't believe me just listen with netcat.
 
Old 10-30-2004, 02:46 PM   #13
overbored
Member
 
Registered: Jun 2003
Posts: 58

Original Poster
Rep: Reputation: 15
tonit, i will try that out once i can access the box again.
 
Old 10-30-2004, 04:26 PM   #14
cetialphav
Member
 
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88

Rep: Reputation: 16
You mean listen with tcpdump (or ethereal). I did. It is not the server that closes the connection. The TCP connection is closed by the client (nc) and not the server. Are you using the -w option to netcat?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
building netcat fowlerlfc Linux - Newbie 0 09-28-2004 08:50 PM
Netcat question igor8 Linux - Security 3 06-21-2004 12:55 PM
netcat install? Di0de Linux - Software 4 11-04-2003 10:52 AM
Anyone Familiar With Netcat ? Santorres Linux - Software 0 07-10-2003 06:27 PM
Anyone Familiar With Netcat ? Santorres Linux - Software 0 07-10-2003 06:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration