Skip to content

Instantly share code, notes, and snippets.

@pmakholm
Created April 15, 2009 17:00
Show Gist options
  • Save pmakholm/95897 to your computer and use it in GitHub Desktop.
Save pmakholm/95897 to your computer and use it in GitHub Desktop.
Simple script to 'cat' an UDP port
#!/usr/bin/perl
# quick and dirty: Read from a udp socket and print to STDOUT
# usage: udpcat.pl <host> <port>
# or: udpcat.pl <host>:<port>
use strict;
use warnings;
use IO::Socket::INET;
my $local = shift;
$local .= ":" . shift unless $local =~ /:/;
my $socket = IO::Socket::INET->new(
LocalAddr => $local,
Proto => 'udp',
ReuseAddr => 1,
) or die $!;
my $buffer;
while( defined( $socket->recv($buffer, 1024) )) {
print $buffer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment