20. my $port = $option{'p'};
21. my $listen = IO::Socket::INET->new(Proto => 'tcp',
24. Reuse => 1) or die "Listen on port $port error: $!n";
26. while( my $client_sock = $listen->accept() )
28. &ProcessData( $client_sock );
32. # if has no -l argument, maybe want to connect to other host
39. my $client_sock = IO::Socket::INET->new(Proto => 'tcp', PeerHost => $ARGV[0], PeerPort => $ARGV[1] ) || die "Connect to $ARGV[0]:$ARGV[1] error:$!n";
40. &ProcessData( $client_sock );
44. my $client_sock = shift;
46. my $select = IO::Select->new( );
48. $select->add( *STDIN );
49. $select->add( $client_sock );
54. if( ! $select->exists( $client_sock ) )
56. print "waiting connection....n";
60. my @ready = $select->can_read;
62. for my $tmp_sock(@ready)
64. if( $tmp_sock eq *STDIN )
66. if( my $recv_len = sysread( *STDIN, $buffer, 1024 ) )
68. if( ! syswrite($client_sock, $buffer) )
70. $select->remove( $client_sock );
71. $select->remove( *STDIN );
72. close( $client_sock );
79. $select->remove( $client_sock );
80. $select->remove( *STDIN );
81. close( $client_sock );
87. elsif( $tmp_sock eq $client_sock )
89. if( my $recv_len = sysread( $client_sock, $buffer, 1024*5 ) )
91. if( ! syswrite( *STDOUT, $buffer) )
93. $select->remove( $client_sock );
94. $select->remove( *STDIN );
95. close( $client_sock );
102. print "socket disconnected.n";
103. $select->remove( $client_sock );
104. $select->remove( *STDIN );
105. close( $client_sock );
116. print "simple nc.pl, code by wustyunshu@hotmail.comn";
117. print "this script don't support -e cmd.exe, ^_^n";
119. print "t -l -p 99n";
120. print "t 192.168.0.1 80n";