Difference between revisions of "Netcat"

From Linuxintro
imported>ThorstenStaerk
(Created page with "netcat lets you stream data of almost any kind across a tcp connection. For example, let's say you have two machines of similar configuration and you want to replicate the hard d...")
 
imported>ThorstenStaerk
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
netcat lets you stream data of almost any kind across a tcp connection. For example, let's say you have two machines of similar configuration and you want to replicate the hard drive of one over to the other; you want to copy the "template" machine to a "target" machine.Given that both machines are online and the '''target''' machine has an IP of 192.168.1.2 you can do this:  
+
netcat lets you stream data over a [[network]] connection. This has several usecases:
 +
 
 +
= hard drive cloning =
 +
Let's say you have two machines of similar configuration and you want to [[clone]] the hard drive of one over to the other; you want to copy the "template" machine to a "target" machine. Given that both machines are online and the '''target''' machine has an IP of 192.168.1.2 you can do this:  
  
 
On the target machine
 
On the target machine
 +
<source>
 
  $ nc -l -p 8000 | dd of=/dev/hda1
 
  $ nc -l -p 8000 | dd of=/dev/hda1
''The target machine is now listening on port 8000. Anything it receives it will write to the first partition of the first drive (hda1)''.
+
</source>
 +
;''The target machine is now listening on port 8000. Anything it receives it will write to the first partition of the first drive (hda1)''.
  
 
On the template machine
 
On the template machine
 +
<source>
 
  $ dd if=/dev/hda1 | nc 192.168.1.2 8000
 
  $ dd if=/dev/hda1 | nc 192.168.1.2 8000
''The first partition of the template machine is read and piped to netcat, which sends it to the IP address and correct port of the target machine.''
+
</source>
 +
;''The first partition of the template machine is read and piped to netcat, which sends it to the IP address and correct port of the target machine.''
 +
 
 +
If you use this technique don't forget the [http://wiki.linuxquestions.org/wiki/MBR Master Boot Record]. You can copy it with:
 +
<source>
 +
$ dd if=/dev/hda bs=446 count=1
 +
</source>
  
If you use this technique don't forget the [[Master Boot Record]]. You can copy it with:
+
= snmp monitoring with UDP =
  $ [[dd]] if=/dev/hda bs=446 count=1
+
You can also monitor network traffic by using netcat as data consumer. To listen to [[snmp]]'s trap communication via UDP set up a SNMP trap receiver using
 +
<source>
 +
  netcat -u -l 162 | hexdump -C
 +
</source>
  
 
= See also =
 
= See also =
 
* [[nmap]]
 
* [[nmap]]
* [[wireshark]]
 
 
* [[tcpdump]]
 
* [[tcpdump]]
 
* [[netstat]]
 
* [[netstat]]

Latest revision as of 13:44, 15 April 2020

netcat lets you stream data over a network connection. This has several usecases:

hard drive cloning

Let's say you have two machines of similar configuration and you want to clone the hard drive of one over to the other; you want to copy the "template" machine to a "target" machine. Given that both machines are online and the target machine has an IP of 192.168.1.2 you can do this:

On the target machine <source>

$ nc -l -p 8000 | dd of=/dev/hda1

</source>

The target machine is now listening on port 8000. Anything it receives it will write to the first partition of the first drive (hda1).

On the template machine <source>

$ dd if=/dev/hda1 | nc 192.168.1.2 8000

</source>

The first partition of the template machine is read and piped to netcat, which sends it to the IP address and correct port of the target machine.

If you use this technique don't forget the Master Boot Record. You can copy it with: <source>

$ dd if=/dev/hda bs=446 count=1

</source>

snmp monitoring with UDP

You can also monitor network traffic by using netcat as data consumer. To listen to snmp's trap communication via UDP set up a SNMP trap receiver using <source>

netcat -u -l 162 | hexdump -C

</source>

See also