Linux/Netcat

From Omnia
Jump to navigation Jump to search

Netcat

Netcat

Copy files from machine foo to bar on port 3333 (-l, listen):

user@bar$ nc -l -p 3333 > backup.iso
user@foo$ nc bar 3333 < backup.iso 

Open a raw connection to port 25 (like telnet):

nc mail.server.net 25

Check if UDP ports (-u) 80-90 are open on 192.168.0.1 using zero mode I/O (-z):

nc -vzu 192.168.0.1 80-90

References:

Copy Disk Across Network

ref: https://www.cyberciti.biz/tips/howto-copy-compressed-drive-image-over-network.html

netcat -p 2222 -l |bzip2 -d | dd of=/dev/sdb
bzip2 -c /dev/sda | netcat hostA 2222


nc -l 2222 | bzip2 -d > /dev/sdb
bzip2 -c /dev/sda | nc 192.168.1.1 2222
# for performance:
netcat -p 2222 -l |bzip2 -d | dd of=/dev/sdb bs=16M

Sending Email with Netcat

ref: Sending Email with Netcat | Linux Journal

Use the command:

date '+%a, %d %b %Y %H:%M:%S %z'

To generate a date string that resembles:

Mon, 12 Apr 2010 14:21:26 -0400

The contents of your message file should resemble this example:

HELO host.example.com
MAIL FROM: <test@host.example.com>
RCPT TO: <bob@example.com>
DATA
From: [Alice] <alice@geek.com>
To: <bob@example.com>
Date: Mon, 12 Apr 2010 14:21:26 -0400
Subject: Test Message

Hi there! This is supposed to be a real email...

Have a good day!
Alice


.
QUIT

Now feed message to netcat:

/usr/bin/nc smtp.domain.com 25 < /tmp/message