login | register
Tue 09 of Feb, 2010 [21:31 UTC]

voip-info.org

Discuss [5] History

Asterisk NetCID

Created by: bromont,Last modification on Wed 21 of Mar, 2007 [05:13 UTC]
NetCID is a free network callerid popup program from Imptec and can be used with an AGI script called from Asterisk for talking callerid notification.

NetCID can be downloaded here:

place the following script in /var/lib/asterisk/agi-bin/

ncid.agi:
  1. !/usr/bin/perl
use Socket;

open STDOUT, '>/dev/null';
fork and exit;

my $timedata = localtime(time);
my $cidnum = $ARGV[0];
my $cidname = $ARGV[1];

my $MSG1 = "STAT Get the Phone!!!";
my $MSG2 = "RING";
my $MSG3 = "NAME $cidname";
my $MSG4 = "TTSN Call from $cidname";
my $MSG5 = "NMBR $cidnum";
my $MSG6 = "TYPE U";
my $MSG7 = "IDLE $timedata";

my $ipaddr=192.168.0.255;
my $portnum=42685;

socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname("udp")) or die "socket: $!";
setsockopt(SOCKET, SOL_SOCKET, SO_BROADCAST, 1) or die "setsockopt: $!\n";
send(SOCKET, $MSG1, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
send(SOCKET, $MSG2, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
send(SOCKET, $MSG3, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
send(SOCKET, $MSG4, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
send(SOCKET, $MSG5, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
send(SOCKET, $MSG6, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
sleep(5);
send(SOCKET, $MSG2, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
sleep(5);
send(SOCKET, $MSG7, 0, sockaddr_in($portnum,$ipaddr)) or die "cannot send to $HOSTNAME($PORTNO): $!";
close(SOCKET);
exit;


Next add a line to your extensions.conf:

exten => s,1,NoOp(Call from:${CALLERID(all)})
exten => s,n,AGI(ncid.agi|${CALLERID(num)}|${CALLERID(name)})
exten => s,n,Dial(${HOUSEPHONES},,t)
exten => s,n,Hangup



Comments

Comments Filter
222

333The same, in Python

by vincentdelporte, Sunday 03 of February, 2008 [06:51:09 UTC]
For those interested, here's my Python version of this Perl script:

  1. !/usr/bin/python

import socket,sys,time,os

def sendstuff(data):
       s.sendto(data,(ipaddr,portnum))
       return

try:
       cidnum = sys.argv1
except:
       #Wiki removes the left and right brackets before the argument index!
       print "Format: " . sys.argv0 . " cidnum cidname"
       sys.exit(1)

try:
       cidname = sys.argv2
except:
       print "Format: " . sys.argv0 . " cidnum cidname"
       sys.exit(1)

sys.stdout = open(os.devnull, 'w')
if os.fork():
       sys.exit(0)

now = time.localtime(time.time())
dateandtime = time.strftime("NaVm/%y NaVM", now)

myarray = []
myarray.append("STAT Rings: 1")
myarray.append("RING")
myarray.append("NAME " + cidname)
myarray.append("TTSN Call from " + cidname)
myarray.append("NMBR " + cidnum)
myarray.append("TYPE K")

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,True)

portnum = 42685
ipaddr = "192.168.0.255"

for i in myarray:
       sendstuff(i)
time.sleep(5)
sendstuff("IDLE " + dateandtime)

222

333

by bromont, Sunday 03 of December, 2006 [07:13:16 UTC]

Asterisk waits until the script finishes without those two lines. We want Asterisk to launch the script then fork the script off to return to dialplan excution.
222

333

by vincentdelporte, Monday 27 of November, 2006 [00:20:09 UTC]
I rewrote the script in Python because I'm more used to it than Perl, and would like to add some features I need.

Are those two lines necessary?

open STDOUT, '>/dev/null';
fork and exit;
222

333Re: No values ?!

by bromont, Monday 20 of November, 2006 [18:52:23 UTC]
Looks like the wiki was interpreting the square bracket after the ARGV values as a link. I've fixed this on the page.
222

333No values ?!

by alexwaller, Saturday 18 of November, 2006 [17:51:58 UTC]
I get a popup with no data. Wenn I try it from prompt, it works!

Asterisk says:
   — Executing AGI("SIP/41-081b3378", "ncid.agi|41|Alexander") in new stack
   — Launched AGI Script /var/lib/asterisk/agi-bin/ncid.agi
   — AGI Script ncid.agi completed, returning 0

What could be wrong?