CLI way of getting bulk handler information

(United States) #1

Hello all,

I am working on a script to automate some of my phone\networking-related task. One of them being, mapping out phones and extensions to a network port. For example, x1001 with mac address for John Doe is in Room 1, and on the networking switch 1 on port1. I store room information in the Account Code section under the extension when the extension is created.

What I have been doing is going into bulk handler and manually downloading “extension” and “clearly devices” into a folder and parsing the data with my script.

My question is I want to automate the bulk handler part of this. Is there a to get the same type of information from the bulk handler from the command line?

asterisk -rx 'database show'
is what I am thinking but trying to see if there is an easier method I might be missing before I got down that route.


Would this help :-

arp-scan 192.168.n.n/x

(Itzik) #3

Take a look at the FreePBX API.

Good article and references here:

(United States) #4

I am already using the arp table and MAC address table from the script to identify what MAC address is plugged into each port. But I need a way to identify x1001 belongs to John Doe with XXXX.YYYY.ZZZZ MAC address. My use case for this is if a user emails in saying my phone is not working. I can quick run my script identify John Doe is at x1001 and his phone is plugged into XX port on switch, then reboot the phone via switch. That usually fixes 90% of the problems.

I work for a school district so we have a lot of movement during the year.

(United States) #5

This article looks promising. I’m more a powershell guy but I will take a look at this.


If the user’s email they complain from maps to their voicemail email address then /etc/asterisk/voicemail.conf would be a direct one to one lookup.

(United States) #7

Thanks for that, that would be one place to look for an extension and email address. What about cross-reference the extension to Mac address? I realized I am using the clearly IP module which might be in a different place, but for example, if it was for Endpoint manager instead?


Not familiar with either EPM or Clearly, but I assume that for either, the provisioning files , likely in /tftpboot , should provide that mapping from file name (mac address tied) and its content ( which would vary by phone hardware)

(Andrew) #9

Most device manufacturers have a setting to add a MAC to the Useragent on a registered device, so you could query it directly from an extension that way.


But the complaint was “my phone’s not working” :slight_smile: Further the phone might be two nats further away.

(Daniel Friedman) #11

Hello @longqvo,

Do you need to pull out the data in the accountcode field? Do you use SIP or PJSIP extensions?

Thank you,

Daniel Friedman
Trixton LTD.

(United States) #12

@danielf currently I am pulling data from bulk handler export of extension are Extension, Name, email address, account code. I also pull Device which give me extension and MAC address. Lastly I gather which phone are currently online with ‘pjsip show endpoints’.

From there I have a script the parse all my switch nightly and maps the Mac addresses to port.

(Daniel Friedman) #13

Hello @longqvo,

So you managed to pull the accountcode data from your pjsip endoints? Do you need any help?

Thank you,

Daniel Friedman
Trixton LTD.

(United States) #14

@danielf So I am manually pulling it from bulk handler exports CSV currently. My script will then parse the csv for the information I need. But I need to remember to pull this, since I am not the only one that uses this script or add/remove/modify extensions. I sometimes forgot to update the bulk handler info.

I am looking for help to do this in the cli, similar to the ‘pjsip show endpoints’ command, which I can add into my nightly script.

(Daniel Friedman) #15

Hello @longqvo,

Which Freepbx version are you using?

Thank you,

Daniel Friedman
Trixton LTD.

(United States) #16

I’m using v15. I think I got something with the show database command.

asterisk -rx 'database show' | egrep "accountcode|cidname"

this outputs

/AMPUSER/1001/cidname : John Doe
/AMPUSER/1001/accountcode : Site-Room 1


If you are using the EPM, the config files probably have most of the info you want. For example - for polycom phones the config files have the MAC address in the name, and the config file has the name and extension number in it. Then you could look up in the voicemail.conf file to get the email address.
Alternatively, look in the mysql DB for the things you want…

(United States) #18

MySQL!! That didn’t even occur to me. I will have to look into that. This sounds really promising.

(Itzik) #19

You may also want to take a look at this:


MAC addresses are baked into the phone, any relationship to an IP address is technically ephemeral unless you either hard-wire that in your DHCP service or your end point manager is demanding a particular one (which would be rash to say the least) I again suggest that the answer can be derived by locating the extension name in a particular config file resulting in an extension keyed to a mac-address in your arp-scan