7 ms·
Netcat – The swiss army knife of networking
- kaeso 14y agoI couldn't really survive without socat: http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES
- smtddr 14y agoseriously, I was introduced to socat about 5 months ago... blew my mind. netcat is good and I still use it to quickly send custom GET requests, but socat is like a swiss-army knife containing many swiss-army knives. It even forwards unix-domain sockets and doesn't necessarily need root permissions like iptables.
- DrPhish 14y agoAgreed. If netcat is the swiss-army knife of network tools, socat is the complete utility belt. I discovered socat because netcat simply wouldn't bend in all the ways I needed it to. There is NOTHING ad-hoc network related that I haven't been able to perform with socat.
- dleimbach 14y agoI connected an SNMP monitoring system using two socats and an ssh tunnel. One socat to forward UDP over TCP to the locally encrypted port, and another to take it off on the other side and forward it to a local SNMP listener. It was a for a control system we were building that could monitor temperatures and control fan speeds in a computer cooling system. We ran it across several states in the US, and it was just to get an early demo of how the system would work before hardware was more locally available and the damned thing worked... This made a lot of people very happy and it was really crazy to be on the phone with the other folks and have them rev up the fans in our lab via SNMP through this channel.
- calinet6 14y agoNo better way to get the absolute maximum possible use of your pipe with the absolute minimum amount of security! Netcat has saved my butt when that 12GB package absolutely, positively has to be there within the next minute. One of the coolest network utilities around. It's literally like a cat piped through the network. These are all great examples.
- cnvogel 14y ago/me too/ I like it (tar|nc) as a quick alternative when moving data to or from low performance devices such as Android phones. Rsync/SSH really burns a lot of power for encryption. Makes a full x GB Backup much faster to pipe it through netcat (or bashs /dev/tcp if available).
- philsnow 14y agothis can help re CPU usage: rsync -e "ssh -c blowfish" However, I'm not sure if anybody uses this these days, since end-to-end time is probably dominated by bandwidth and not cpu these days.
- c-oreills 14y agoIf that's your use case then have a look at ncp: http://www.fefe.de/ncp/ http://www.fefe.de/ncp/ From the site: '"ncp" is a utility for copying files in a LAN. It has absolutely no security or integrity checking, no throttling, no features, except one: you don't have to type the coordinates of your peer.'
- calinet6 14y agoSweet :) I wasn't doing it over lan though, totally different subnets here. It's easy to quickly open the port I want to use for netcat on a remote machine and copy files quickly that way. If you're interested in completely saturating all your resources for the maximum possible transfer speed, check out Tsunami: http://tsunami-udp.sourceforge.net/ http://tsunami-udp.sourceforge.net/ -- It's a UDP protocol designed for raw throughput. Also no security or checking, but it does support throttling which is nice. I've tested and it actually does exceed netcat's rate by a few percent, but it's a little less reliable (client and server have to agree on a lot of things). Pretty cool to experiment with though :)
- kylecordes 14y agoAs an alternative to all of the above, consider UDPCast. It's point is that it can multicast; but it is also great for point-to-point copies. I adds its own reliability layer, so don't be scared of UDP in the name. It can rate limit, if you want. I've used it to great effect to shuffle a lot of GB to a bunch of servers at the time. Way down at a low level, the network hardware/firmware knows how to send data 1:N. Using that is a single easy command away, but hardly anyone knows it. http://kylecordes.com/2008/multicast-your-db-backups-with-udpcast http://kylecordes.com/2008/multicast-your-db-backups-with-ud...
- c-oreills 14y agoSee also ncat - netcat for the 21st century: http://nmap.org/ncat/ http://nmap.org/ncat/
- peterwwillis 14y agoThis is what everyone should be using instead of 'nc'. SSL, SCTP, IPv6, proxying, hex dump, keep open, waits, and more. I wouldn't call 'socat' a swiss army knife. More like a tool shed. But it is very handy at times.
- pjmlp 14y agoExcept it is not Linux specific, rather a UNIX born utility.
- fduran 14y agoJust in case: if you like ncat and networking tools check out also scapy http://www.secdev.org/projects/scapy/demo.html http://www.secdev.org/projects/scapy/demo.html
- 3am 14y agoIn the situations where nc is useful then scapy is probably not an option. Nc, dd, and a few others are almost always present and great when you are in a real bind... something went wrong in a network install in pxelinux, and you want to copy off dumps or config files, or copy on a missing file. Otherwise, there are better ways to do most of the things mentioned in the article, most involving scp. EDIT: the number of responses to this article happily highlighting the lack of security in netcat just terrifies me. EDIT2: Ah, I see what you were saying (and scapy is an awfully cool library). It was just a convenient place for me to highlight was I didn't think was highlighted enough in the article: nc can do neat things, but not much that can't be accomplished better with other tools - its big advantage is that it's almost always present, even if ssh/scp, rsync, netstat, wget/curl, etc are not. Like using cat + sed as a text editor :)
- fduran 14y agoI know they are different tools, I meant if you like to play with ncat, tcpdump etc and/or you're learning netsec you may want to play with scapy. Directed to the very few readers that may know about nc and not scapy :-)
- chm 14y agoIt seems there are better alternatives to netcat, i.e. socat and ncat. Why should I choose either? I'd like to learn how to use such a tool, but I'm not a CS major.
- cnvogel 14y agoFor the simple task of moving bytes through a tcp connection (what the article is about) netcat will be fine. Socat allows you to use raw interfaces, or fifos, SSL, proxies, serial ports,... as one or both end points. E.g. you can forward arbitrary tcp connections (tcp relay;) but also connect stdin/stdout if a program to a serial port... just very, very, very versatile. http://www.dest-unreach.org/socat/doc/socat.html http://www.dest-unreach.org/socat/doc/socat.html
- chm 14y agoThank you.
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]
- sigil 14y agoNetwork REPL, with autocomplete and history: rlwrap nc ....
- runejuhl 14y agoIt should be noted that rlwrap works on all programs that use readline. I've used it when starting out with programming in SML and getting annoyed at the missing arrow-up command history.
- thomaslutz 14y agoNginx - the swiss army knife to avoid webserver overloading after getting frontpaged on HN (currently seeing error 500 from Apache only).
- jimktrains2 14y agoI really don't see how Apache vs Nginx will give you that much performance increase. The majority of the processing time for a request is in the backend (rendering, compiling, db calls, &c). Improved caching would give much better performance gains than just switching a server without any other improvements.
- thomaslutz 14y agoCompare memory usage; also Apache has problems with many concurrent connections and low hard limits as default, which nginx handles much better. Varnish of course would also be a valid improvement.
- nisa 14y agoApache can fill your 100Mbit line just fine for most cases. It's Wordpress where 98% of your processing time is spend. Switching to nginx does not help at all in most cases. I really like nginx but Apache gets a lot of unfounded hate.
- djrobstep 14y agoI used to think this too, but I recently switched a PHP app I run over to Nginx from Apache, nginx uses much less memory, and consequently the app can run on far less instances, it's been a huge win. This app has many long-running connections and a write-heavy workload, your mileage may vary.
- amenghra 14y agomake sure you checkout socat. It's netcat on steroids (http://www.dest-unreach.org/socat/ http://www.dest-unreach.org/socat/)
- matugm 14y agoI love socat, way more powerful than netcat, it also supports SSL and IPv6, I wrote about some netcat to socat examples here http://www.blackbytes.info/2012/07/socat-cheatsheet/ http://www.blackbytes.info/2012/07/socat-cheatsheet/
- est 14y agoand it supports sctp.
- vinhboy 14y agoThis really cool. I have always wondered if there was tool to quickly open a chat between two computers. It's nice to learn about this.
- jnazario 14y agonc is ancient but flexible. want encryption? pipe in openssl's command line to encrypt a stream. i'm pleased to see it so widely deployed. for fun, find the original hobbit nc source code and read the comments. the complaints in there about writing a portable utility and dealing with platforms' weirdness and brokenness.
- deleted 14y ago[deleted]
- 3am 14y agoI think PowerShell has its own idiom for doing this. You might want to look into BITS (and related PS cmdlets), too.
- gtrubetskoy 14y agoWhy is it a Linux netcat command? What about the FreeBSD netcat or the Solaris one?
- ajross 14y agoActually the netcat shipped on most/all common Linux distributions (though IIRC, frustratingly not Cygwin which has a more limited one without the SOCKS features) is the one from OpenBSD. But obviously the article was written from the perspective of "Fun commands available on Linux". I'm all for giving proper credit where it is due, but it's asking a little too much to expect that every newbie tutorial is going to inflict a full software genealogy on the poor reader...
- zyberkiddy 14y agoFew months earlier, when I was learning shell programming, I created a simple file transfer script using netcat (nc) and zenity (for little GUI).. Can be used to transfer files inside LAN.. It was actually made to use inside our college lab for my non technical friends.. https://github.com/zyberkiddy/netcat-file-transfer https://github.com/zyberkiddy/netcat-file-transfer
- NoodleIncident 14y agoSite's down. Didn't know that HN hugged so hard...
- mhb 14y agoPlenty of other previous mentions here for you to peruse: https://www.hnsearch.com/search#request/submissions&q=netcat&start=0 https://www.hnsearch.com/search#request/submissions&q=ne...
- stiff 14y agoNgrep is another awesome tool that is a networking equivalent of a common UNIX utility (although a more loose one in this case): http://ngrep.sourceforge.net/ http://ngrep.sourceforge.net/ Also +1 for socat as a netcat replacement, having SSL there when needed is really helpful. I use it a lot for testing when developing network applications, replacing one end point with a fixed set of responses or even typing stuff in interactively etc.
- sliverstorm 14y agoMy favorite use of nc to date: cat disk.img > nc nc > /dev/sda
- NegativeK 14y agoThis is basically #7, and I found it particularly handy when Ghost barfed on my source image. Since we had an entire lab to clone to, we combined dd, netcat, and tee to just daisy chain the data out. It worked _magically_.
- Jtsummers 14y agoThat was exactly my experience, and I nearly wrote the same thing. Frustrating day saved by 2 simple commands.
- nodata 14y agoDo you mean to use >redirect, or did you mean |pipe?
- 4ad 14y agoOn Plan 9, where networked I/O is done through a file system, there is no need for netcat, you can use regular Plan 9 tools to do anything netcat does and more. I miss this dearly on Unix.
- coolsunglasses 14y agoThere are two kinds of operating systems, those that people use and those that people don't complain about.
- ancarda 14y agoI can't seem to get the chat example to work on OS X. Does anyone know if it's limited to working on Linux? [Edit] I was using nc 127.0.0.1 so I'm not sure if netcat can't communicate with lo. Also tried SSHing into a Linux box I own, now I get "Connection refused" on the client side (OS X). [Edit Again] UDP works fine! Server: nc -ul -p <Port> Client: nc -u <IP> <Port>