An Introduction to Linphone

I have been looking for a softphone for some time now with two requirements: (1) easy to use GUI; and (2) can easily be used from command line. Many softphones have great GUIs, which are easy to use and very friendly. The second part, easy to use from command line, was a tricky requirement. The idea is to make a complete call from the command line in an interactive way. For example, dial a number, enter options to any IVRs, and then hangup once done. However, I had another requirement: be able to script this whole thing as well.

Linphone is a softphone that met my requirements. It is very easy to use. I was able to use its GUI to create SIP accounts and register with Asterisk and FreeSWITCH, and make calls easily. But there are two things which make this the complete package for me.

The first is linphonec. It’s a command line program which lets you make calls, etc. interactively. Just run the program, it registers with the appropriate servers, and then you can issue commands to make and control calls.

The second is linphonecsh. This is what finally sold me on this product. Using some very simple steps, one can script the whole behavior of one (or more, if desired) calls. Linphonecsh is actually a daemon for linphonec. You can read how to control it from Control a linphonec daemon from scripts. Although that’s the official page, for those of us too lazy to click a link, below are the main steps:

Start the daemon: linphonecsh init
Register with SIP provider: linphonecsh register --host --username 100 --password mypassword
Check status of registration: linphonecsh status register
Call a number: linphonecsh dial ""
Disconnect call: linphonecsh hangup
Stop the daemon: linphonecsh exit

I had a problem. I wanted to register Linphone to an Asterisk server on the LAN. I used the following command to register (I am omitting the init, etc. as they are understood).

linphonecsh register --host --username 100 --password mypassword

But linphonecsh status register would show register=-1. I tried many things but nothing worked. Searching led me to Linphonecsh register problem. I didn’t really understand what I was doing wrong. I finally figured it out.

If you look at ~/.linphonerc file, you will notice that the word realm is used. For me it was realm="asterisk". The way I understand it, realm in the file is the same as --host in the register command. In other words, if realm is “asterisk” then --host should not be an IP address but it should be a hostname.

With this idea in mind, I created an entry in /etc/hosts file for mapping to asterisk. And I modified my register command to the following. It worked!

linphonecsh register --host asterisk --username 100 --password mypassword

So if you are having problems registering linphonecsh to an Asterisk server, try this. Maybe it will solve your problem. I mean, it’s not just with Asterisk; the solution may work for other servers also. Of course, if the server is not on your LAN, you should use its domain name instead of IP for --host.

8 Responses to An Introduction to Linphone

  1. Pingback: » Blog Archive » An Introduction to Linphone « Code Ghar - Just another WordPress weblog

  2. Rudi says:

    Hi there, I am following your instructions and i am having the exact same problem. I tired your fix for editing the hosts file. And on my Elastix box it shows i am registered, but still can’t make calls through linphonecsh. linphonec works fine. Still get registerd= -1. Any help would or ideas would be appreciated.

    Kind Regards

    Rudi Steenberg

  3. hs says:

    What does your “realm” say in the .linphonerc file? Did you use that as hostname in both your hosts file and the linphonecsh register command?

  4. Tobias says:

    I have the same Problem i can register linphone and linphonec to my Cisco callmanager.
    But if i try to register with linphonecsh it doesn’t work. I Tried to use your solution but it does not work.
    realm = ccmsipline
    i added this to my hosts and tried to register :(

  5. ogols says:

    linphonesh generic “sip:1000@ password”

  6. ogols says:

    linphonesh generic “register sip:1000@ password”

  7. pantaraf says:

    Thanks for sharing!!! It worked for me! ;-)

  8. Guillermo says:

    I have been working on some scripts that I would like to share ;)

    We have done a LAMP CRM system + asterisk + linphonecsh commands.

    The Hotkeys to execute Shell / Bash commands are (works with icewm):
    Pick Up call, Hang up call, Swap between a Streaming running call and a Paused call.

    It could be great to publish these commands on linphone developers PAGE!
    These scripts are working incredible for us!

    FILE: /home/.icewm/keys
    key “Ctrl+1” linphonecsh init
    key “Ctrl+2” linphonecsh register –host asterisk –username YOURUSERNAME –password YOURPASSWORD
    key “Ctrl+0” linphonecsh exit

    key “Ctrl+Up” /home/guillermo/pickup
    key “Ctrl+Down” /home/guillermo/hangup
    key “Ctrl+s” /home/guillermo/swap

    FILE: home/.icewm/startup
    linphonecsh init
    sleep 4
    linphonecsh register –host asterisk –username YOURUSERNAME –password YOURPASSWORD

    FILE: home/pickup
    # Pickup calls linphonecsh

    linphonecsh generic calls | grep -E ‘IncomingReceived’ | awk ‘{ print $1 ” ” $5 ” ” $6 ” ” }’ | tr -d ‘|’ >hanguparchive

    # grep search incoming calls

    awk -v qt=”‘” ‘{

    # Vars definition
    estado1=$2; id1=$1;

    system (“linphonecsh generic ” qt “answer ” id1 qt );

    }’ hanguparchive

    FILE: home/hangup
    # Hangup calls linphonecsh

    linphonecsh generic calls | grep -E ‘StreamsRunning’ | awk ‘{ print $1 ” ” $5 ” ” $6 ” ” }’ | tr -d ‘|’ >hangdownarchive

    awk -v qt=”‘” ‘{

    # Vars definition
    estado1=$2; id1=$1;

    system (“linphonecsh generic ” qt “terminate ” id1 qt );

    }’ hangdownarchive

    FILE: home/swap

    linphonecsh generic calls | grep -E ‘Paused|StreamsRunning’ | awk ‘{ print $1 ” ” $5 ” ” $6 ” ” }’ | tr -d ‘\n’ | tr -d ‘|’ >callsarchive

    awk -v qt=”‘” ‘{

    # Var definitions (estado = status)
    estado1=$2; estado2=$4; id1=$1; id2=$3;

    # Si hay 2 llamadas activas:
    if ((estado1)&&(estado2)) {

    # case 1: status1 Active (or running) and 2 paused
    if ((estado1==”StreamsRunning”)&&(estado2==”Paused”)){
    system (“linphonecsh generic ” qt “pause ” id1 qt );
    #system (“sleep 0.4”);
    system (“linphonecsh generic ” qt “resume ” id2 qt );

    # case 2: status1 Paused and 2 Running
    if ((estado1==”Paused”)&&(estado2==”StreamsRunning”)){
    system (“linphonecsh generic ” qt “pause ” id2 qt );
    #system (“sleep 0.4”);
    system (“linphonecsh generic ” qt “resume ” id1 qt );

    # case 3: both calls in paused
    if ((estado1==”Paused”)&&(estado2==”Paused”)){
    system (“linphonecsh generic ” qt “resume ” id1 qt );

    # case 4: both calls are active
    if ((estado1==”StreamsRunning”)&&(estado2==”StreamsRunning”)){
    system (“linphonecsh generic ” qt “pause ” id2 qt );

    # Only one call running

    if (estado1==”Paused”){
    system (“linphonecsh generic ” qt “resume ” id1 qt );
    if (estado1==”StreamsRunning”){
    system (“linphonecsh generic ” qt “pause ” id1 qt );

    }’ callsarchive

%d bloggers like this: