Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
The stupid question is the question not asked

Poor mans Netcat

by Corion (Pope)
on Nov 04, 2003 at 12:17 UTC ( #304388=perlcraft: print w/ replies, xml ) Need Help??

   1: #!/usr/bin/perl -w
   2: # As our unix printer setup is weird and I sometimes want to
   3: # print to networked (HP) printers, I needed something like
   4: # netcat. I was unsatisfied with <tt>telnet</tt>, as it did
   5: # output stuff I didn't want, and I didn't want to add the
   6: # redirection to /dev/null. Perl to the rescue:
   8: use strict;
   9: use IO::Socket;
  11: select IO::Socket::INET->new(PeerAddr => shift, PeerPort => (shift || 23));
  12: print
  13:   for <>;
  15: __END__
  16: # or, as a oneliner:
  17: perl -MIO::Socket -pe 'BEGIN{select IO::Socket::INET->new(PeerAddr=>shift,PeerPort =>(shift||23))}'

Comment on Poor mans Netcat
Download Code
Re: Poor mans Netcat
by Samveen (Initiate) on Nov 07, 2013 at 11:00 UTC

    To add to the above, the equivalent of listening using netcat (netcat -l) to push data is

    1: #!/usr/bin/perl -w 2: # No nc -l on SunOS 5.8 DMZed host to transfer data out. 3: # Perl to the rescue: 4: 5: use strict; 6: use IO::Socket; 7: 8: select IO::Socket::INET->new(LocalPort=>(shift||2222), Listen=>1 +)->accept; 9: 10: print 11: for <>; 12: 13: __END__ 14: # or, as a oneliner: 15: perl -MIO::Socket -pe 'BEGIN{select IO::Socket::INET->new(LocalP +ort=>(shift||2222), Listen=>1)->accept;}'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlcraft [id://304388]
Approved by barrd
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2014-04-18 17:44 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (471 votes), past polls