netcat

2
Mike’s FreeBSD Stuff: Netcat Examples Netcat is a great little network tool for a variety of tasks especially transferring files. Its included with most BSD distros & versions are available for mac/win, just google... If you’re using netcat on a home-network behind a router/firewall, netcat can act as a server *only within your home network* (although it can still connect to outside servers as a client). To serve data outside your home-network, you’ll need to configure your router/firewall to forward a port outside your LAN. But consider this: When you forward a port in this manner, you’re exposing your home-network to the outside world... To use netcat as a server, you’ll need to provide an ip-number. Either your local address for use solely within your LAN, or your public address for use outside your LAN. . to obtain your local ip-number under windows invoke: ’ipconfig’ . under unix & osx use: ’ifconfig’ . to obtain your public ip-number check your router settings . or google using a query such as: ’what is my ip’ Here’s some example uses for netcat, I’ve used port 3333, but you can instead use most any port you like. And (of course) there may be differences with your particular build of netcat, RTFM for details. . one time file transfer server: nc -l -p 3333 < file.in client: nc [server-address] 3333 > file.out . streaming media using mpg123 [1] server: type *.mp3 | nc -l -p 3333 client: nc [server-address] 3333 | mpg123 - . chat server, keyboard acts as stdin, ^C to terminate server: nc -l -p 3333 client: nc [server-address] 3333 . remote shell unix server: nc -l -p 3333 -e /bin/sh client: nc [server-address] 3333

Upload: sjmpak

Post on 06-Nov-2015

213 views

Category:

Documents


0 download

DESCRIPTION

IT

TRANSCRIPT

  • Mikes FreeBSD Stuff: Netcat Examples

    Netcat is a great little network tool for a variety of tasks especially transferring files. Its included with most BSD distros & versions are available for mac/win, just google... If youre using netcat on a home-network behind a router/firewall, netcat can act as a server *only within your home network* (although it can still connect to outside servers as a client). To serve data outside your home-network, youll need to configure your router/firewall to forward a port outside your LAN. But consider this: When you forward a port in this manner, youre exposing your home-network to the outside world...

    To use netcat as a server, youll need to provide an ip-number. Either your local address for use solely within your LAN, or your public address for use outside your LAN.

    . to obtain your local ip-number under windows invoke: ipconfig

    . under unix & osx use: ifconfig

    . to obtain your public ip-number check your router settings

    . or google using a query such as: what is my ip

    Heres some example uses for netcat, Ive used port 3333, but you can instead use most any port you like. And (of course) there may be differences with your particular build of netcat, RTFM for details.

    . one time file transfer

    server: nc -l -p 3333 < file.in client: nc [server-address] 3333 > file.out

    . streaming media using mpg123 [1]

    server: type *.mp3 | nc -l -p 3333 client: nc [server-address] 3333 | mpg123 -

    . chat server, keyboard acts as stdin, ^C to terminate

    server: nc -l -p 3333 client: nc [server-address] 3333

    . remote shell unix

    server: nc -l -p 3333 -e /bin/sh client: nc [server-address] 3333

  • . remote shell win

    server: nc -l -p 3333 -e cmd.exe client: nc [server-address] 3333

    . compressed pipe using gnu-tar

    server: tar -czf - * | netcat -l -p 3333 client: nc [server-address] 3333 | tar -xzf -

    . compressed pipe using info-zip [2]

    server: zip - *.* | nc -l -p 3333 client: nc [server-address] 3333 | unzip -

    . windows continuous file server, iterates once per connection

    @echo off cls :start nc -w 3 -l -p 3333 < file goto start

    . unix continuous file server, iterates once per connection

    #!/bin/sh while true; nc -w 3 -l -p 3333 < file; done

    . relay incoming traffic on port 3333 to another address/port

    server: nc -l -p 3333 | nc [relay-address] [relay-port]

    . notes

    [1] mpg123 mp3 player available here: http://www.mpg123.de

    [2] Info-Zip archiver available here: http://www.info-zip.org

    [c]2014 Mike Sanders http://freebsd.hypermart.net All rights reserved.