impromptu web server using netcat

David J Berube djberube at berubeconsulting.com
Sun Jan 14 12:51:09 EST 2007


Note that the second sentence should have read "displaying the file 
instead of saving it."

Take it easy,

David Berube
Berube Consulting
djberube at berubeconsulting.com
(603)-485-9622
http://www.berubeconsulting.com/

David J Berube wrote:
> Slick. Suppose you wanted to download a file using this kind of server 
> onto an IE machine, but the browser kept viewing the file instead of 
> displaying it. You should be able to do this:
> 
> 
> (echo HTTP/1.0 200 OK; echo 'Content-Disposition: attachment; 
> filename="some_filename.pdf"'; echo; cat some_filename.pdf) | nc -l -p 8080
> 
> That should force the "save as or open" dialog.
> 
> Take it easy,
> 
> David Berube
> Berube Consulting
> djberube at berubeconsulting.com
> (603)-485-9622
> http://www.berubeconsulting.com/
> 
> aluminumsulfate at earthlink.net wrote:
>> 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
>> _______________________________________________
>> gnhlug-discuss mailing list
>> gnhlug-discuss at mail.gnhlug.org
>> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
>>
>>
> _______________________________________________
> gnhlug-discuss mailing list
> gnhlug-discuss at mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
> 
> 


More information about the gnhlug-discuss mailing list