Computer Telephony Integration (CTI)
CTI is the way the Office Telephone Station can provide real-time information to computer-aided workplaces about the call and to accept control from various SoftPhones.
I have Samsung iDCS 500 in the office and it offers CTI stream with information about all extension events including calling and called party number (both internal extention number and external city phone number).
cti.lsp is a newLISP library that allows to get and parse CTI stream.
Documentation