Command line dialing on Cisco 7940/7960 IP Phone

I decided to share my perl script which I am using to dial numbers on my Cisco 7960 from command line. It can be used for integration with callto:// links, PIM or just to dial from console. To dial script using telnet interface on the phone, so it must be enabled. Script using “test” which emulates buttons on the phone. Pause between commands is required to work correctly, without it phone will go mad.

#!/usr/bin/perl

use Net::Telnet;
use Time::HiRes;

# cisco phone host name
my $host='10.0.0.1';
# cisco phone password
my $password='cisco';
# mute on a dial 0/1
my $mute=0;

my $sleeptime=.2;
my $prompt='/> $/';

my $argc = @ARGV;
if ($argc!=1){
    print "Usage: call.pl <number>\n";
    exit;
}
my $number=@ARGV[0];

if($number!~/^[0-9*#]+$/) {
    print "Error: wrong characters in the numer\n";
    exit 2;
}
$telnet = new Net::Telnet ( Timeout=>3, Errmode=>'die');
# connecting
$telnet->open($host);
$telnet->waitfor('/Password :$/i'); 
$telnet->print($password); 
$telnet->waitfor($prompt);

$telnet->print('test open');
$telnet->waitfor($prompt);
$telnet->print('test key spkr');
$telnet->waitfor($prompt);Time::HiRes::sleep($sleeptime);
if($mute){
    $telnet->print('test key mute');
    $telnet->waitfor($prompt);Time::HiRes::sleep($sleeptime);
}
$telnet->print("test key ".$number."#");
$telnet->waitfor($prompt);Time::HiRes::sleep((length($number)+1)*$sleeptime);
$telnet->print('test close');
$telnet->waitfor($prompt);
$telnet->close($host);
Advertisements
Tagged , , ,

7 thoughts on “Command line dialing on Cisco 7940/7960 IP Phone

  1. Thank you … that’s what i search

  2. Weiss Benjamin says:

    I added the following two lines to delete blanks and replace ‘+’ with ’00’.

    $number =~ s/[ ]| //gi;
    $number =~ s/[+]/00/g;

    With the following AppleScript I can now make calls directly from my Mac OS X Address Book.

    using terms from application “Address Book”
    on action property
    return “phone”
    end action property

    on action title for aPerson with phoneNumber
    return (“Call ” & (value of phoneNumber as string))
    end action title

    on should enable action for aPerson with phoneNumber
    return true
    end should enable action

    on perform action for aPerson with phoneNumber
    do shell script “perl /my/script/location/dialer.pl ‘” & (value of phoneNumber as string) & “‘”
    end perform action
    end using terms from

    Works like a charm. Thanks for your work.

    • sammczk says:

      Thank you for your comment ) Yes, it could be used for different purposes, including callto links, dialing from PIM or integration with CRM, for example. I am glad that it is also helpful for MacOSX users.

  3. Weiss Benjamin says:

    A little bit more elegant:

    # Replace first ‘+’ with ’00’ and delete everything else but Numbers, ‘*’ and ‘#’
    $number =~ s/[+]/00/;
    $number =~ s/[^0-9*#]//g;

  4. […] Continue reading here: Command line dialing on Cisco 7940/7960 IP Phone « smallhacks […]

  5. […] script will dial into bridge and then enter conference id + # sign. For the Cisco 7940/7960 users my old script with minimal changes should work […]

  6. […] now we need to add the PERL script that will do the dialling. I pinched this from smallhacks which is an excellent guide. Click here to see the original post, and thanks to smallhacks for it. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: