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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-30-2004, 05:14 AM
|
#1
|
Member
Registered: Jun 2003
Posts: 58
Rep:
|
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.
|
|
|
10-30-2004, 06:33 AM
|
#2
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
and
Code:
echo 'foo' | nc -q0 othermachine 7421
|
|
|
10-30-2004, 12:36 PM
|
#3
|
Member
Registered: Jun 2003
Posts: 58
Original Poster
Rep:
|
the server is NOT netcat. and i already said there's no -q.
|
|
|
10-30-2004, 01:12 PM
|
#4
|
Member
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88
Rep:
|
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.
|
|
|
10-30-2004, 01:27 PM
|
#5
|
Member
Registered: Jun 2003
Posts: 58
Original Poster
Rep:
|
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.
|
|
|
10-30-2004, 01:43 PM
|
#6
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
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.
|
|
|
10-30-2004, 01:45 PM
|
#7
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
Oh... you already did that, too.
Why the building from debian sources failed?
|
|
|
10-30-2004, 02:03 PM
|
#8
|
Member
Registered: Jun 2003
Posts: 58
Original Poster
Rep:
|
as i mentioned...  i need to run it on is a fedora box.
|
|
|
10-30-2004, 02:22 PM
|
#9
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
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
|
|
|
10-30-2004, 02:31 PM
|
#10
|
Member
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88
Rep:
|
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?
|
|
|
10-30-2004, 02:35 PM
|
#11
|
Senior Member
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357
Rep:
|
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
|
|
|
10-30-2004, 02:35 PM
|
#12
|
Member
Registered: Jun 2003
Posts: 58
Original Poster
Rep:
|
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.
|
|
|
10-30-2004, 02:46 PM
|
#13
|
Member
Registered: Jun 2003
Posts: 58
Original Poster
Rep:
|
tonit, i will try that out once i can access the box again.
|
|
|
10-30-2004, 04:26 PM
|
#14
|
Member
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88
Rep:
|
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?
|
|
|
All times are GMT -5. The time now is 10:39 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|