<?xml version="1.0" encoding="windows-1252"?>
<node id="335489" title="Help With Custom War Dialer" created="2004-03-10 10:59:09" updated="2005-07-28 12:37:00">
<type id="115">
perlquestion</type>
<author id="225273">
Dru</author>
<data>
<field name="doctext">
Greetings Monks,&lt;br&gt;&lt;br&gt;

Recently, I was given the task of finding all modems at my companies location. I've used the war dialer &lt;a href="http://www.securityfocus.com/tools/47/scoreit" taget="_blank"&gt;THC-Scan&lt;/a&gt; in the past with good results, but for some reason this time I went to use it and it failed to detect any modems even when they where present. I tried the other popular dialer &lt;a href="http://www.securityfocus.com/tools/48" target="_blank"&gt;Toneloc&lt;/a&gt;, but I could not get it working correctly. &lt;br&gt;&lt;br&gt;

I then thought "I wonder if there is a Perl module that will help me roll my own." And sure enough, I found [cpan://Win32::SerialPort]. Hacking an &lt;a href="http://members.aol.com/Bbirthisel/pager_files.txt" target="_blank"&gt;example&lt;/a&gt; from the author's site, I was able to get almost what I wanted. When it detects a modem, I receive the following: &lt;code&gt;Output: Got ."ATDT123456789&lt;/code&gt;, which is great since I can just send all the output to a file and just parse on ATDT to get a list of modems.&lt;br&gt;&lt;br&gt;

But knowing my manager, he's going to ask "Is there anyway to tell if they are faxes or not." Since faxes sound distinctively different, I'm wondering if this is possible? 
&lt;br&gt;&lt;br&gt;

Any help is much appreciated,&lt;br&gt;
Dru
&lt;code&gt;
# The majority of this code is borrowed from:
# http://members.aol.com/Bbirthisel/pager_files.txt
# I just removed the parts to let it run unattended.

use Win32::SerialPort;

use strict;
use warnings;

my ($line, $port, $port_obj, $string, $timeout);

my $paging_service = "123456789";	# Supply real number here

my $debug = 1;

$port = 'COM3';

# Open port with previously saved configuration
$port_obj = start Win32::SerialPort ("pager_$port.cfg") 
   || die "Can't open pager_$port.cfg: $^E\n";

print STDERR "Dialing Number: \"$paging_service\"\n" if $debug;

# You probably need at least BUSY and CONNECT
$port_obj-&gt;are_match("BUSY","CONNECT","OK",
     "NO DIALTONE","ERROR","RING","NO CARRIER","NO ANSWER");

# my modem resets to give verbose responses
$port_obj-&gt;write("ATZ\r") || die "Could Not Reset\n";
# Check Modem responding to reset

# 5 second timeout from config file
waitfor() || die "Modem Did Not Reset\n";

# Timeouts will need adjustment for dfferent services and locations.
# Must give the receiving modem a few seconds to pickup and negotiate.
$port_obj-&gt;read_const_time(30000);

my $retries = 0;
for (;;) {
    $port_obj-&gt;write("ATDT$paging_service\r") 
                || die "Could Not Dial\n";
    # Dial Paging service
    my $diallog = waitfor();
    die "Dial timed out or failed\n" unless (defined $diallog);
    last if ($diallog eq "CONNECT");
    if ((++$retries &lt; 5) &amp;&amp; ($diallog eq "BUSY")) {
        sleep 1; # adjust as required
        next;
    }
    die "Dial did not connect properly: $diallog\n"
}

$port_obj-&gt;write("\r\r");
# Hit enter when connected

$port_obj-&gt;read_const_time(10000);

$port_obj-&gt;read_const_time(5000);

## waitfor("Goodbye\r") || die "Missing signoff from service\n";
waitfor("Goodbye") || die "Missing signoff from service\n";

$port_obj-&gt;close;                                                   
# Close port


sub waitfor {
    $port_obj-&gt;lookclear;  # clear buffers
    my $gotit = "";
    my $response = shift;
    if ($response) {
        $port_obj-&gt;are_match($response);
        print "Output: Waiting for \"$response\".\n" if $debug;
    }
    else {
        print "Output: Waiting for \"are_match()\".\n" if $debug;
    }

    for (;;) {
        return unless (defined ($gotit = $port_obj-&gt;lookfor(1)));
        if ($gotit ne "") {
            my ($match, $after, $pattern) = $port_obj-&gt;lastlook;
            print "Output: Got .\"$gotit$match$after\".\n" if $debug;
            return $match;
        }
        return if ($port_obj-&gt;reset_error);
    }
}
&lt;/code&gt;

</field>
</data>
</node>
