Howto create a Hotline bot in Perl using Net::Hotline::Client


Hotline is a software platform for file sharing (not peer to peer). It attracts more of an “underground” community, which saw it as an easier to use successor to the Internet Relay Chat (IRC) community. This article introduces the Perl hotline client module and explains how to use it to implement a basic hotline bot that connects to a hotline server and performs a few basic operations.


The Net::Hotline::Client module

Net::Hotline::Client is a class implementing a Hotline internet client in Perl. It was specifically developed to aid in the creation of Hotline “bots,” although it's suitable for most other tasks as well. Hotline is an internet client/server system that's sort of a cross between IRC and a BBS.

To install the module, you can use CPAN as follows:

$cpan
>cpan get Net::Hotline::Client
>cpan make Net::Hotline::Client
>cpan install Net::Hotline::Client
>cpan quit

If you are not using the system wide cpan repository, you can tell perl the location of the installed module using the PERL5LIB environment variable.

If you are using bash, you will need to issue a command like this :

export PERL5LIB=/path/to/home/dir/lib/perl5/site_perl/5.8.7

A basic bot example : Listing files in a hotline server

The following scripts uses the Net::Hotline::Client module to list all files in a given hotline server.

#! /usr/bin/perl
 
use Net::Hotline::Client;
 
$hlc = new Net::Hotline::Client;
$hlc->connect("82.108.12.9");
 
$hlc->login(Login    => "guest",
Password => "guest",
Nickname => "--nick",
Icon     => 128);
 
sub print_tree {
 
my ($dir)=@_;
 
print $dir."\n";           # Ex: "Uploads:Pictures"
 
$hlc->blocking_tasks(1);   # Set blocking / nonblocking
 
# Contact the server to obtain the list of files
$hlc->get_filelist($dir) || return;
 
$content = $hlc->files();  # Get reference to the file tree
 
foreach $item (@{$content->{$dir}})
{
 
      if ($dir) {
         $fullpath=$dir.':'.$item->name; }
      else {
         $fullpath=$item->name; }
 
      print_tree($fullpath);
}
 
}
 
 
print_tree("");

Other functions provided by the Hotline Perl module


Downloading a file

FunctionDescription
downloads_dir PATHSets the directory where downloaded files are placed to PATH (if present). Returns the current setting.
get_file PATHDownload the file on the server located at PATH to the local directory set via downloads_dir()
get_file_resume PATHResume downloading the file on the server located at PATH to the local directory set via downloads_dir(). The partially downloaded file(s) must exist in the local download directory
recv_file TASK, REF, SIZEStarts receiving the file designated by the Net::Hotline::Task object TASK, the download reference number REF, and the size in bytes SIZE returned by get_file()

Example :

downloads_dir ("/tmp");
($task, $ref, $size) = $hlc->get_file("Folder1:file.jpeg");
 
/* If resuming file download :
($task, $ref, $size) = $hlc->get_file_resume("Folder1:file.jpeg");*/
 
$hlc->recv_file($task, $ref, $size);

Uploading a file

FunctionDescription
put_file SRC_PATH, DEST_PATH, COMMENTUpload the file located at SRC_PATH to the server directory DEST_PATH, with the file comments COMMENT. SRC_PATH must be in the native path format of the local system (i.e. using ”:” as the path separator on Mac OS, and ”/” on most other OSes). DEST_PATH must be in Hotline's native path format (”:” as the path separator)
put_file_resume SRC_PATH, DEST_PATH, COMMENTResume uploading the file located at SRC_PATH to the server directory DEST_PATH, with the file comments COMMENT
send_file TASK, REF, SIZE, RFLTStarts sending the file designated by the Net::Hotline::Task object TASK, the upload reference number REF, the size in bytes SIZE, and the resume information RFLT returned by put_file(). Returns 1 if the upload completed successfully, or undef if there was an error.

Example :

($task, $ref, $size) = $hlc->put_file("/home/john/file.gz",  "Folder1:Folder2", "A fun file!");
 
/* If resuming an upload
($task, $ref, $size, $rflt) = $hlc->put_file_resume("/home /john/file.gz", "Folder1:Folder2", "A fun file!");*/
 
$hlc->send_file($task, $ref, $size);

For more details about the perl hotline module check the online documentation from CPAN.



Labels: , Wireless Internet Security Coding Network Monitoring

Comment

Enter your comment (wiki syntax is allowed):
VFHXE

Wireless Internet Security Performance RADIUS server Wireless Internet Security Performance RADIUS server