A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label nc. Show all posts
Showing posts with label nc. Show all posts

Perl telnet script OR netcat

When you need to test using telnet, but don't have telnet installed, and you do have Perl:

use strict;
use warnings;

my $usage = "usage: $0 host port\n";

my $host = $ARGV[0] or die $usage;
my $port = $ARGV[1] or die $usage;

use Net::Telnet ();
my $t = new Net::Telnet (
        Port    => $port,
        Timeout => 5,
);
$t->open($host);

my $print_success = $t->print("GET / HTTP/1.0\n");
print "sent command: $print_success\n";

my @lines = $t->getlines(Timeout => 2);

print @lines;

OR an even easier way with netcat:

fprint "GET / HTTP/1.0\n\n" | nc host port