impromptu web server using netcat

aluminumsulfate at earthlink.net aluminumsulfate at earthlink.net
Sun Jan 14 12:16:46 EST 2007


Hi, All...

Most of you are probably familiar with the ever useful TCP/IP utility
"netcat" (often /usr/bin/nc).  It's real handy for doing quick and
easy file transfers, or otherwise tossing bytes about on a network.
It runs on most variants of UNIX (including Linux) and there's even a
version for Win32.

Those of you who have ever tried to transfer a file between 'doze and
'nix know how hard it can be... create and mount a shared folder or
samba share, set up an httpd or ftpd, install putty, third-party file
transfer websites, AIM file transfer, etc.  - all HORRIBLY inelegant
AND time-consuming solutions.  The win32 port of netcat has been
*invaluable* in this kind of situation, allowing simple file transfer
between Windows and Linux machines, using one (relatively) simple
command and only one small additional executable (nc.exe).

You can find a copy of Win32 netcat at:

  ftp://ftp.dbnet.ece.ntua.gr/pub/users/george/nc.exe

or extract the nc.exe file from the tarball at:

 http://gd.tuwien.ac.at/gnu/gnu-win32/release/netcat/netcat-1.10-2.tar.bz2

Unfortunately, the popular Win32 version of netcat requires a DLL
named ast54.dll, which seems to be missing on some versions of XP
Professional.  Having recently been faced with such a problem, I tried
what may seem an insane solution: using netcat to pose as a web
server!

As it turns out, it's not only possible but also quite simple to
create a simple web server using netcat:

 $ (echo HTTP/1.0 200 OK; echo; echo 'Hello, world!') | nc -l -p 8080

A web browser pointed at port 8080 will then retrieve the content
"Hello, world!" and display it in the browser window like any other
web page.  This technique can be used to transfer any kind of file
(text, binary, tar archive, etc.) and has been confirmed to work with
Firefox.  Would anyone care to test against IE?

Yeah, it's kind of a loopey solution, but it's still relatively
simple.  Additionally, it requires NO extra software of the target
machine - not even netcat.  All that's required on the receiving
machine is a web browser.

Would anyone be up for implementing a netcat server for HTTP PUT?  :D


More information about the gnhlug-discuss mailing list