c0defellas / enzo

core utilities
11 stars 2 forks source link

netcat #26

Open katcipis opened 7 years ago

katcipis commented 7 years ago

Lets develop an nc. Should work with:

So we can hack the shit out of stuff :-)

i4ki commented 7 years ago

What annoys me the most is that netcat implementations only handle one connection at time. GNU nc have some advanced support for multiple connections but as far as I remember it sucks...

What about:

# listen to tcp port 8080 and send 'response.dump' to first client connection
$ cat response.dump | nc -stats -l tcp://:8080 
Remote client: 192.168.10.56:48500
Bytes sent: 486
TCP Connection: 30ms
Content transfer: 2ms
Done
$
# -repeat handle multiple connections
$ cat response.dump | nc -stats -repeat -listen tcp://:8080 
Press CTRL-D to abort...

Remote client: 192.168.10.56:48500
Bytes sent: 486
TCP Connection: 30ms
Content transfer: 2ms
Done
Remote client: 192.168.10.56:42196
Bytes sent: 486
TCP Connection: 30ms
Content transfer: 2ms
Done
^D
$
i4ki commented 7 years ago

Another idea, maybe it sucks but who knows... is add support for HTTP protocol out of the box... it's everywhere and rule the IT world...

Something like below could be interesting:

$ cat input.json | nc http://www.jsonlint.com/indent
{
        "data": "test",
        "data2": "test2"
}
$

And, the most nice:

# serve index.html to every HTTP connection on port 8080
$ cat index.html | nc -repeat -listen http://0.0.0.0:8080
Press CTRL-D to abort...
^D

# Serve the input files in HTTP port 8080
$ ls | nc -repeat -serve -listen http://0.0.0.0:8080

# or a directory tree
$ find . | nc -repeat -serve -listen http://0.0.0.0:8080

# Instead of serve a directory, serving specific input files avoid path traversal attacks.

Maybe it's too much... I don't know.

katcipis commented 7 years ago

@tiago4orion the http thing I'm also thinking it may be too much, I need time to let the idea grow :-).

About the -repeat option, sounds interesting, but what would be the semantics ? I send the stdin and close the connection or a wait for the other side to close it ? It seems like you are modeling a request/response thing, but nc would be more general than this no ?