Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

netcat-like stdio to tcp "proxy"? [SOLVED]

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
4 posts • Page 1 of 1
Author
Message
Sadako
Advocate
Advocate
User avatar
Posts: 3792
Joined: Thu Aug 05, 2004 5:50 pm
Location: sleeping in the bathtub
Contact:
Contact Sadako
Website

netcat-like stdio to tcp "proxy"? [SOLVED]

  • Quote

Post by Sadako » Thu Jun 01, 2017 8:53 pm

I'm playing around with http requests from shell, and I have a working script with both bash's networking and by using netcat/socat with named pipes, but, both nc and socat terminate after one http request and response...

I`m looking for a solution where "proxy" I'm using will keep running and accept new connections after the first one, something neither nc nor socat seems to support unless binding to an ip address.

Running nc or socat within a while loop would do the trick, but I'm looking for something "cleaner", or more efficient, and ideas?

In case it's unclear, this is what I'm using;

Code: Select all

nc 127.0.0.1 8080 < nc_in > nc_out
with nc_in and nc_out two named pipes or fifos.

Thanks.
Last edited by Sadako on Sat Jun 03, 2017 3:52 pm, edited 1 time in total.
"You have to invite me in"
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Fri Jun 02, 2017 6:11 pm

net-misc/s6-networking?
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Fri Jun 02, 2017 6:44 pm

Server-side nc:
--continuous Enable continuous accepting of connections in listen mode, like inetd. Must be used with --exec to specify the command to run locally (try 'nc6 --continuous --exec cat -l -p <port>' to make a simple echo server).
If you want to have many sources use a single netcat client, you can have it read from a fifo. Fifo terminates when the last program on either end exits, and it can be used by many programs at the same time. This means, you can use some idling process to keep the fifo open (say '( read; ) > fifo' ) and then you can even write with echo >fifo and it will not terminate connection even though it exits instantly.
Still, even though sharing a single connection is possible, I'd rather go with one instance of nc/curl/anything per task.
Top
Sadako
Advocate
Advocate
User avatar
Posts: 3792
Joined: Thu Aug 05, 2004 5:50 pm
Location: sleeping in the bathtub
Contact:
Contact Sadako
Website

  • Quote

Post by Sadako » Sat Jun 03, 2017 3:52 pm

Thank you both very much for your responses, as it turns out I was looking at this wrong, the actual problem was that the http server was closing the connection after serving a single request, which is why netcat was exiting.

I was just testing with busybox httpd, which doesn't support http keep-alive (but I actually knew that, so I have no excuse really...).

Testing with lighttpd and adding the "Connection: keep-alive" header, it just works exactly as I wanted.
szatox wrote:If you want to have many sources use a single netcat client, you can have it read from a fifo. Fifo terminates when the last program on either end exits, and it can be used by many programs at the same time. This means, you can use some idling process to keep the fifo open (say '( read; ) > fifo' ) and then you can even write with echo >fifo and it will not terminate connection even though it exits instantly.
Yeah, what I was doing was opening a file descriptor to the named pipes I had redirected netcat's stdin and stdout to in the shell script.
Still, even though sharing a single connection is possible, I'd rather go with one instance of nc/curl/anything per task.
Generally, I completely agree on this, but there are always exceptions. ;)

Anyways, ty both again.
"You have to invite me in"
Top
Post Reply

4 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic