Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

nc and dd not working

Posted on 2011-09-24
4
Medium Priority
?
353 Views
Last Modified: 2012-05-12
hi

Receiving server :

 nc -l -p 1234 | dd of=/dev/sda

netstat -ant
tcp        0      0 0.0.0.0:1234            0.0.0.0:*               LISTEN


Sending Server :

dd if=/dev/hda | nc 192.0.0.33 1234


but it does not do any transfer ..


while investigating i can see it connects ..

example :

After typing both command in both server ..

if i press Ctrl + c  ( to break the connection)

now if i do netstat in receiving server

tcp        0      0 192.0.0.33:1234        192.0.0.11:52288        ESTABLISHED

i can see there is establish connection , its only after pressing "control C"

when i will press Again Control +c.
then receiving server

 nc -l -p 1234 | dd of=/dev/sda
128+0 records in
128+0 records out
65536 bytes (66 kB) copied, 96.2275 s, 0.7 kB/s


so the connection establisehd after pressing Control +c Second time .. data does not transfer..


is there any bug or something ??

this command works :

Sending server :  cat backup.sh | nc -vv -l -p 3333

Receving server : nc 192.0.0.137 3333 > backup.sh


both server has same version of nc running ..

any workway round will be really usefull

thanks



0
Comment
Question by:fosiul01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 21

Assisted Solution

by:Daniel McAllister
Daniel McAllister earned 1000 total points
ID: 36594179
From the man page for nc:
-l      Used to specify that nc should listen for an incoming connection
             rather than initiate a connection to a remote host.  It is an
             error to use this option in conjunction with the -p, -s, or -z
             options.  Additionally, any timeouts specified with the -w option
             are ignored.

So, the correct syntax for the listening endpoint (which apparently has an IP of 192.0.0.33) would be:
nc -l 1234 | dd of=/dev/sda

and the correct syntax for the sending endpoint would be:
dd if=/dev/sda | nc 192.0.0.33 1234

NOTE: This will make the TCP network connection work -- I make no argument or guarantee that the dd portion of this will correctly copy an entire disk from point a to point b... personally, I would use an rsync command, or in a pinch, a tar tunneled through an ssh (or an nc) command.

Just my initial thoughts looking at this... let me know if it still doesn't work!

Dan
IT4SOHO

PS: I am assuming as well that the listening endpoint is either not using a firewall (iptables) or has a rule in place for port 1234....

0
 
LVL 29

Author Comment

by:fosiul01
ID: 36597514
hi Sorry did not see the post ..



if i use live cd example
knoppix in both server then i use command


Receiving server :

 nc -l -p 1234 | dd of=/dev/sda

netstat -ant
tcp        0      0 0.0.0.0:1234            0.0.0.0:*               LISTEN


Sending Server :

dd if=/dev/hda | nc 192.0.0.33 1234


it works perfectly ..

but lenny its not working ..
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1000 total points
ID: 36598541
Hi again fosiul,

if I remember well we had the same case some time ago, and again if I remember well, I told you to use
the "-w" option at the sending end to have the connection terminated  after 1 second of network inactivity (i.e. after transfer is complete)..

Background: What you describe is quite normal netcat behaviour. It will never come to and end if you don't set a timeout or terminate it via Ctl-C.

You can verify this by not redirecting the output at the receiving (listening) end. You'll see the output appear immediately on the screen, but you will not see netcat terminate if you don't use the timeout (or Ctl-C).

wmp

0
 
LVL 29

Author Comment

by:fosiul01
ID: 36954775
Hi WMP

yes, just remembered about that post..

i will try with that again to see how it works.. but because i did not have time .. i had to take both server offline then use live CD and then use dd + netcat to copy data

its works fine with live cd (knopxis)

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question